<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>linux与shell编程 | 九问Blog</title>
    <meta name="description" content="欢迎访问九问Blog！分享一些Python全栈开发以及爬虫技术，希望对你有所帮助">
    <meta name="generator" content="VitePress v1.6.4">
    <link rel="preload stylesheet" href="/assets/style.DFMv0UyT.css" as="style">
    <link rel="preload stylesheet" href="/vp-icons.css" as="style">
    
    <script type="module" src="/assets/app.FY3_6mXQ.js"></script>
    <link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/assets/chunks/theme.C5KTugK_.js">
    <link rel="modulepreload" href="/assets/chunks/framework.CKMM7nwK.js">
    <link rel="modulepreload" href="/assets/Linux_Linux基础入门.md.pHBVwgKW.lean.js">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><!--[--><div class="Layout" data-v-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0b0ada53></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0b0ada53>Skip to content</a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar" data-v-ae24b3ad data-v-6aa21345><div class="wrapper" data-v-6aa21345><div class="container" data-v-6aa21345><div class="title" data-v-6aa21345><div class="VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-1168a8e4><a class="title" href="/" data-v-1168a8e4><!--[--><!--]--><!----><span data-v-1168a8e4>九问Blog</span><!--[--><!--]--></a></div></div><div class="content" data-v-6aa21345><div class="content-body" data-v-6aa21345><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6aa21345><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963><span id="main-nav-aria-label" class="visually-hidden" data-v-dc692963> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E5%B7%A5%E5%85%B7/Git/%E5%90%8C%E6%97%B6%E6%8E%A8%E9%80%81Gitee%E5%92%8CGitHub.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>工具</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/Linux/Linux%E5%9F%BA%E7%A1%80%E5%85%A5%E9%97%A8.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Linux</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E7%88%AC%E8%99%AB/%E5%AF%BC%E8%AE%BA.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>爬虫</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E6%B5%8B%E8%AF%95/faker%E6%95%B0%E6%8D%AE%E9%9A%8F%E6%9C%BA%E7%94%9F%E6%88%90.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>测试</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/Python/%E5%8E%9F%E7%90%86%E7%B1%BB/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Python</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/Python%E6%A1%86%E6%9E%B6/Django/%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Python框架</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E5%85%B6%E4%BB%96/%E5%85%AB%E8%82%A1/Linux.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>其他</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E5%89%8D%E7%AB%AF/Vue3/axios.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>前端</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/LLM/LangChain/quick_start.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>LLM</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/docker/mysql.html" tabindex="0" data-v-dc692963 data-v-e56f3d57><!--[--><span data-v-e56f3d57>环境搭建</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-6aa21345 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-6aa21345 data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/jiuwen567" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><span class="vpi-social-github"></span></a><a class="VPSocialLink no-icon" href="https://gitee.com/jiuwen567" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><svg t="1724307958358" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4234" width="200" height="200"><path d="M512 0C230.4 0 0 230.4 0 512s230.4 512 512 512 512-230.4 512-512S793.6 0 512 0z m284.8 313.6c0 12.8-12.8 25.6-25.6 25.6H416c-41.6 0-76.8 35.2-76.8 76.8v243.2c0 12.8 12.8 25.6 25.6 25.6h240c41.6 0 76.8-35.2 76.8-76.8v-12.8c0-12.8-12.8-25.6-25.6-25.6H480c-12.8 0-25.6-12.8-25.6-25.6v-64c0-12.8 12.8-25.6 25.6-25.6h291.2c12.8 0 25.6 12.8 25.6 25.6v144c0 92.8-76.8 169.6-169.6 169.6H252.8c-12.8 0-25.6-12.8-25.6-25.6V412.8C227.2 310.4 310.4 224 416 224h355.2c12.8 0 25.6 12.8 25.6 25.6v64z" fill="#B32225" p-id="4235"></path></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-6aa21345 data-v-bb2aa2f0 data-v-cf11d7a2><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-cf11d7a2><span class="vpi-more-horizontal icon" data-v-cf11d7a2></span></button><div class="menu" data-v-cf11d7a2><div class="VPMenu" data-v-cf11d7a2 data-v-b98bc113><!----><!--[--><!--[--><!----><div class="group" data-v-bb2aa2f0><div class="item appearance" data-v-bb2aa2f0><p class="label" data-v-bb2aa2f0>主题</p><div class="appearance-action" data-v-bb2aa2f0><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-bb2aa2f0 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div></div></div><div class="group" data-v-bb2aa2f0><div class="item social-links" data-v-bb2aa2f0><div class="VPSocialLinks social-links-list" data-v-bb2aa2f0 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/jiuwen567" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><span class="vpi-social-github"></span></a><a class="VPSocialLink no-icon" href="https://gitee.com/jiuwen567" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-bd121fe5><svg t="1724307958358" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4234" width="200" height="200"><path d="M512 0C230.4 0 0 230.4 0 512s230.4 512 512 512 512-230.4 512-512S793.6 0 512 0z m284.8 313.6c0 12.8-12.8 25.6-25.6 25.6H416c-41.6 0-76.8 35.2-76.8 76.8v243.2c0 12.8 12.8 25.6 25.6 25.6h240c41.6 0 76.8-35.2 76.8-76.8v-12.8c0-12.8-12.8-25.6-25.6-25.6H480c-12.8 0-25.6-12.8-25.6-25.6v-64c0-12.8 12.8-25.6 25.6-25.6h291.2c12.8 0 25.6 12.8 25.6 25.6v144c0 92.8-76.8 169.6-169.6 169.6H252.8c-12.8 0-25.6-12.8-25.6-25.6V412.8C227.2 310.4 310.4 224 416 224h355.2c12.8 0 25.6 12.8 25.6 25.6v64z" fill="#B32225" p-id="4235"></path></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6aa21345 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-6aa21345><div class="divider-line" data-v-6aa21345></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>菜单</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-8a42e2b4><button data-v-8a42e2b4>回到顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-319d5ca6><div class="curtain" data-v-319d5ca6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-319d5ca6><span class="visually-hidden" id="sidebar-aria-label" data-v-319d5ca6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-c40bc020><section class="VPSidebarItem level-0 has-active" data-v-c40bc020 data-v-b3fd67f8><!----><div class="items" data-v-b3fd67f8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/Linux/Linux%E5%9F%BA%E7%A1%80%E5%85%A5%E9%97%A8.html" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>Linux基础入门</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/Linux/%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9B%B8%E5%85%B3.html" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>虚拟机相关</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b3fd67f8 data-v-b3fd67f8><div class="item" data-v-b3fd67f8><div class="indicator" data-v-b3fd67f8></div><a class="VPLink link link" href="/Linux/%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%A4%87%E5%BF%98.html" data-v-b3fd67f8><!--[--><p class="text" data-v-b3fd67f8>常用命令备忘</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>On this page</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _Linux_Linux%E5%9F%BA%E7%A1%80%E5%85%A5%E9%97%A8" data-v-39a288b8><div><h1 id="linux与shell编程" tabindex="-1">linux与shell编程 <a class="header-anchor" href="#linux与shell编程" aria-label="Permalink to &quot;linux与shell编程&quot;">​</a></h1><h1 id="第1章-linux概述" tabindex="-1">第1章 Linux概述 <a class="header-anchor" href="#第1章-linux概述" aria-label="Permalink to &quot;第1章 Linux概述&quot;">​</a></h1><h2 id="_1-1-了解unix系统" tabindex="-1">1.1 了解Unix系统 <a class="header-anchor" href="#_1-1-了解unix系统" aria-label="Permalink to &quot;1.1  了解Unix系统&quot;">​</a></h2><p>Unix 是较早被广泛使用的计算机操作系统之一，它的第一版于1969年由 Ken Thompson 在 AT&amp;T 贝尔实验室是实现，1973年 Ken Thompson 与 Dennis Ritchie 用C语言重写了 Unix 的第三版内核</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598337889698.png" alt="1598337071697"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598337459742.png" alt="1598337459742"></p><ul><li>Unix是一个强大的多用户、多任务操作系统。</li><li>UNIX的商标权由国际开放标准组织（The Open Group）所拥有。</li><li>UNIX操作系统是商业版，需要收费，价格比Microsoft Windows正版要贵一些。</li></ul><h2 id="_1-2-了解linux发展历史" tabindex="-1">1.2 了解Linux发展历史 <a class="header-anchor" href="#_1-2-了解linux发展历史" aria-label="Permalink to &quot;1.2 了解Linux发展历史&quot;">​</a></h2><p>Linux是一套自由加开放源代码的类Unix操作系统，诞生于1991年10月5日（第一次正式向外公布），由芬兰学生Linus Torvalds和后来陆续加入的众多爱好者共同开发完成。</p><p>Linux这个词本身只表示Linux内核，但实际上人们已经习惯了用Linux来形容整个基于Linux内核，并且使用GNU 工程各种工具和数据库的操作系统。</p><blockquote><p>GPL协议:</p><p>Richard M.Stallman 于1984年创立自由软件体系GNU，拟定普遍公用版权协议（GeneralPublicLicense，简称GPL），今天Linux的成功就得益于GPL协议。</p><p>所有GPL协议下的自由软件都遵循着Richard M. Stallman的&quot;Copyleft&quot;(非版权)原则：即自由软件允许用户自由拷贝、修改和销售，但是对其源代码的任何修改都必须向所有用户公开。</p></blockquote><blockquote><p>GNU 计划</p><p>GNU计划和自由软件基金会FSF(the Free Software Foundation)是由Richard M. Stallman 于1984 年一手创办的。旨在开发一个类似UNIX 并且是自由软件的完整操作系统</p><p>到上世纪90 年代初，GNU 项目已经开发出许多高质量的免费软件，其中包括有名的emacs 编辑系统、bash shell 程序、gcc 系列编译程序、gdb 调试程序等等。这些软件为Linux 操作系统的开发创造了一个合适的环境。这是Linux 能够诞生的基础之一，以至于目前许多人都将Linux 操作系统称为“GNU/Linux”操作系统。</p></blockquote><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598337738510.png" alt="1598337738510"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598337828588.png" alt="1598337828588"></p><p><strong>Linux 系统特点</strong></p><p>开放性（开源）、多用户、多任务、良好的用户界面、优异的性能和稳定性以及多用户多任务的特点</p><blockquote><p>多用户：多个用户，在登陆计算机（操作系统），允许同时登陆多个用户进行操作</p><p>多任务：多个任务，允许用户同时进行多个操作任务</p><p><strong>注意：Windows 属于单用户多任务，Linux 属于多用户多任务</strong></p></blockquote><h2 id="_1-3-linux的应用领域" tabindex="-1">1.3 Linux的应用领域 <a class="header-anchor" href="#_1-3-linux的应用领域" aria-label="Permalink to &quot;1.3 Linux的应用领域&quot;">​</a></h2><ul><li>服务器系统 <ul><li>Web应用服务器、数据库服务器、游戏服务器、接口服务器、DNS、FTP等等；</li></ul></li><li>嵌入式系统 <ul><li>路由器、防火墙、手机、PDA、IP 分享器、交换器、家电用品的微电脑控制器等等</li></ul></li><li>高性能运算、计算密集型应用 <ul><li>Linux有强大的运算能力。IBM的Watson超级计算机就是使用了Linux系统</li></ul></li><li>桌面应用系统 <ul><li>很多桌面操作系统的底层也是Linux</li></ul></li><li>移动手持系统 <ul><li>安卓系统就是基于Linux</li></ul></li></ul><h2 id="_1-4-linux版本" tabindex="-1">1.4 Linux版本 <a class="header-anchor" href="#_1-4-linux版本" aria-label="Permalink to &quot;1.4 Linux版本&quot;">​</a></h2><p>Linux 的版本继承了 Unix 的版本定制规则，分为内核版本和发行版本</p><p>内核版本：内核就是一个核心，其他软件都基于这个核心，不能直接使用，内核版本统一在 <a href="http://www.linux.org/" target="_blank" rel="noreferrer">http://www.linux.org</a> 发布</p><p>发行版本：由各个 Linux 发行商发布，Linux 发行商有权选择 Linux 的内核版本。常见的 Linux 的发行版本：RedHat、CentOS、Debian、Ubuntu</p><p>内核版本分为稳定版和开发版，区分方式是根据次版本的奇偶判定，奇数为开发版，偶数为稳定版</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps92D5.tmp.jpg" alt="img"></p><ul><li><p>Debian</p><p><code>Debian运行起来极其稳定，这使得它非常适合用于服务器。</code></p></li><li><p>redhat：</p></li></ul><p><code>这是第一款面向商业市场的Linux发行版。它有服务器版本，支持众多处理器架构。 </code></p><p><code>全球最大的linux发行厂商，功能全面、稳定。</code></p><ul><li><p>ubuntu：</p><p><code>Ubuntu是Debian的一款衍生版，侧重于它在这个市场的应用，在服务器、云计算、甚至一些运行</code></p><p><code>的移动设备上很常见。 </code></p></li><li><p>centos：</p><p><code>CentOS是一款企业级Linux发行版，它使用红帽企业级Linux中的免费源代码重新构建而成。这款重构版完全</code></p><p><code>去掉了注册商标以及Binary程序包方面一个非常细微的变化。 </code></p></li><li><p>Fedora</p><p><code>Fedora同是一款非常好的发行版，有庞大的用户论坛，软件库中还有为数不少的软件包。Fedora同样使</code></p><p><code>用YUM来管理软件包。</code></p></li></ul><h1 id="第2章-安装linux" tabindex="-1">第2章 安装Linux <a class="header-anchor" href="#第2章-安装linux" aria-label="Permalink to &quot;第2章 安装Linux&quot;">​</a></h1><h2 id="_2-1-安装虚拟机软件" tabindex="-1">2.1 安装虚拟机软件 <a class="header-anchor" href="#_2-1-安装虚拟机软件" aria-label="Permalink to &quot;2.1 安装虚拟机软件&quot;">​</a></h2><ul><li><p><strong>什么是虚拟</strong></p><p>虚拟机（Virtual Machine）指通过软件模拟的具有完整硬件系统功能的、运行在一个完全<a href="https://baike.baidu.com/item/%E9%9A%94%E7%A6%BB/33079" target="_blank" rel="noreferrer">隔离</a>环境中的完整<a href="https://baike.baidu.com/item/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F/7210959" target="_blank" rel="noreferrer">计算机系统</a>。</p></li><li><p><strong>常用的虚拟机</strong></p><p>常用的虚拟机软件 主要包括：VMware Workstation、 VirtualBox、Virtua* PC</p><p>VMware Workstation: 是VMware公司销售的商业软件产品之一。该工作站软件包含一个用于英特尔x86相容电脑的虚拟机套装，其允许用户同时创建和运行多个x86虚拟机</p><p>VirtualBox: VirtualBox 是一款开源<a href="http://baike.baidu.com/view/2690045.htm" target="_blank" rel="noreferrer">虚拟机软件</a>。VirtualBox 是由德国 Innotek 公司开发，由Sun Microsystems公司出品的软件，使用<a href="http://baike.baidu.com/view/23681.htm" target="_blank" rel="noreferrer">Qt</a>编写，在 Sun 被 <a href="http://baike.baidu.com/view/15020.htm" target="_blank" rel="noreferrer">Oracle</a> 收购后正式更名成 Oracle VM VirtualBox</p><p>Virtua* PC：是Microsoft 最新的虚拟化技术。主要适合做微软自己产品的服务</p></li><li><p><strong>我的电脑与虚拟机</strong></p></li></ul><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1536900815049.png" alt="1536900815049"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532336004455.png" alt="1532336004455"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532336050219.png" alt="1532336050219"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532338442304.png" alt="1532338442304"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532338476057.png" alt="1532338476057"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532338501111.png" alt="1532338501111"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532338521718.png" alt="1532338521718"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532338642018.png" alt="1532338642018"></p><h2 id="_2-2-安装centos-7系统" tabindex="-1">2.2 安装Centos 7系统 <a class="header-anchor" href="#_2-2-安装centos-7系统" aria-label="Permalink to &quot;2.2 安装Centos 7系统&quot;">​</a></h2><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592557694942.png" alt="1592557641329"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592557915169.png" alt="1592557721112"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558419967.png" alt="1592558419967"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558559382.png" alt="1592558559382"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558659233.png" alt="1592558645801"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558696944.png" alt="1592558696944"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558721074.png" alt="1592558721074"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558756005.png" alt="1592558756005"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558778534.png" alt="1592558778534"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558805754.png" alt="1592558805754"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558845772.png" alt="1592558845772"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558954787.png" alt="1592558954787"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592558990803.png" alt="1592558990803"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559427650.png" alt="1592559427650"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559453782.png" alt="1592559453782"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559494779.png" alt="1592559494779"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559646063.png" alt="1592559646063"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559688543.png" alt="1592559688543"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592559723347.png" alt="1592559723347"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560034489.png" alt="1592560034489"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560074473.png" alt="1592560074473"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560097970.png" alt="1592560097970"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560116310.png" alt="1592560116310"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560546189.png" alt="1592560546189"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592560599789.png" alt="1592560599789"></p><h2 id="_2-3-配置静态ip" tabindex="-1">2.3 配置静态IP <a class="header-anchor" href="#_2-3-配置静态ip" aria-label="Permalink to &quot;2.3 配置静态IP&quot;">​</a></h2><p>配置网络的目的主要是为了固定虚拟机的内网IP，方便我们在真实的操作系统中使用Linux连接工具软件进行远程连接。</p><p>1.关闭虚拟机</p><p>2.点击编辑，选择倒数第二个选项“虚拟网络编辑器器”,出现下面的“虚拟网络编辑器器”窗口。选择NAT模式， 注意子网IP前三位与NAT设置的网关IP、DHCP网段一致。</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592566727611.png" alt="1592566727611"></p><p>设置NAT</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592566786436.png" alt="1592566786436"></p><p>设置DHCP范围</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592566864298.png" alt="1592566864298"></p><p>3.进入操作系统配置网卡信息</p><p>执行命令</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>vi /etc/sysconfig/network-scripts/ifcfg-ens33</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592567176167.png" alt="1592567176167"></p><p>保存退出</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>esc退出</span></span>
<span class="line"><span>:wq  保存退出</span></span></code></pre></div><p>4.重启执行命令重启网卡服务</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>systemctl restart network</span></span></code></pre></div><p>5.检查IP是否更变</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>命令:  ip addr</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592567450267.png" alt="1592567450267"></p><ol start="6"><li><p>windows放行 ICMP</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netsh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> advfirewall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> firewall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> add</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> rule</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> name=&quot;ICMP Allow&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> protocol=icmpv4:any,any</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dir=in</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> action=allow</span></span></code></pre></div></li></ol><p>5.测试是否网络是否连通</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>ping www.baidu.com</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592567574316.png" alt="1592567574316"></p><p>说明网络已经连通.</p><h2 id="_2-4-给虚拟机进行快照" tabindex="-1">2.4 给虚拟机进行快照 <a class="header-anchor" href="#_2-4-给虚拟机进行快照" aria-label="Permalink to &quot;2.4 给虚拟机进行快照&quot;">​</a></h2><p>快照其实就是还原点，我们设置了快照。以后如果被我们玩坏了，也可以快速的还原到以前状态！</p><p>VMware快照</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps92EE.tmp.jpg" alt="img"></p><h2 id="_2-5-安装远程连接工具" tabindex="-1">2.5 安装远程连接工具 <a class="header-anchor" href="#_2-5-安装远程连接工具" aria-label="Permalink to &quot;2.5 安装远程连接工具&quot;">​</a></h2><h3 id="_2-5-1-远程终端命令工具" tabindex="-1">2.5.1 远程终端命令工具 <a class="header-anchor" href="#_2-5-1-远程终端命令工具" aria-label="Permalink to &quot;2.5.1 远程终端命令工具&quot;">​</a></h3><p>主要功能是向Linux系统远程发送命令</p><p>Xshell：目前最好用</p><p>SecureCRT：收费</p><p>Putty：早就停止维护了，很多东西支持的很差。但因为习惯依旧很多人支持</p><h3 id="_2-5-2-xmanager工具" tabindex="-1">2.5.2 XManager工具 <a class="header-anchor" href="#_2-5-2-xmanager工具" aria-label="Permalink to &quot;2.5.2 XManager工具&quot;">​</a></h3><p>1)安装过程比较简单下一步</p><p>2)配置主机地址</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293585922.png" alt="1597293585922"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293616973.png" alt="1597293616973"></p><ol start="3"><li>输入用户名和密码</li></ol><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293647929.png" alt="1597293647929"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293700442.png" alt="1597293700442"></p><ol start="4"><li>xshell工作样式配置</li></ol><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293862086.png" alt="1597293862086"></p><ol start="5"><li>xftp 工具使用</li></ol><p>xftp window操作系统和centos 系统传输文件</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597293941740.png" alt="1597293941740"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597294009345.png" alt="1597294009345"></p><h1 id="第3章-linux的结构" tabindex="-1">第3章 Linux的结构 <a class="header-anchor" href="#第3章-linux的结构" aria-label="Permalink to &quot;第3章 Linux的结构&quot;">​</a></h1><h2 id="_3-1-linux组成" tabindex="-1">3.1 Linux组成 <a class="header-anchor" href="#_3-1-linux组成" aria-label="Permalink to &quot;3.1 Linux组成&quot;">​</a></h2><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps9308.tmp.jpg" alt="img"></p><p>内核：是系统的心脏，是运行程序和管理像磁盘和打印机等硬件设备的核心程序。 Shell：是系统的用户界面，提供了用户和内核进行交互操作的一种接口。它接收用户输入的命令并把它送入内核去执行，是一个命令解释器。但它不仅是命令解释器，而且还是高级编程语言，shell编程。 FILE SYSTEMS(文件系统)：文件系统是文件存放在磁盘等存储设备上的组织方法，Linux支持多种文件系统，如ext3,ext2,NFS,SMB,iso9660等</p><p>应用程序：标准的Linux操作系统都会有一套应用程序例如X-Window,Open Office等</p><h2 id="_3-2-linux目录结构" tabindex="-1">3.2 Linux目录结构 <a class="header-anchor" href="#_3-2-linux目录结构" aria-label="Permalink to &quot;3.2 Linux目录结构&quot;">​</a></h2><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/11.png" alt="目录结构"></p><p>注意：</p><pre><code>　　/boot：系统引导文件、内核
　　/bin：用户的基本命令
　　/dev：设备文件
　　/etc：配置文件
　　/home：用户目录
　　/root：root用户目录
　　/sbin：管理类的基本命令
　　/tmp：临时文件存放地
　　/usr：共享的只读数据
　　/mnt：临时文件系统挂载点
　　/media：移动设备挂载点
　　/opt：第三方应用程序的安装位置
　　/srv：系统运行的服务用到的数据
　　/var：变化的数据文件
　　/proc：用于输出内核与进程信息相关的虚拟文件系统
　　/sys：用于输出当前系统上硬件设备相关信息的虚拟文件系统
</code></pre><h1 id="第4章-常用linux命令的基本使用" tabindex="-1">第4章 常用Linux命令的基本使用 <a class="header-anchor" href="#第4章-常用linux命令的基本使用" aria-label="Permalink to &quot;第4章 常用Linux命令的基本使用&quot;">​</a></h1><h2 id="_4-1-常用快捷键" tabindex="-1">4.1 常用快捷键 <a class="header-anchor" href="#_4-1-常用快捷键" aria-label="Permalink to &quot;4.1 常用快捷键&quot;">​</a></h2><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1) tab键：命令或者路径提示及补全;</span></span>
<span class="line"><span></span></span>
<span class="line"><span>2) ctrl+c：放弃当前输入，终止当前任务或程序；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>3) ctrl+l：清屏；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>4) ctrl + insert：复制；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>5) 鼠标右键：粘贴；</span></span>
<span class="line"><span> </span></span>
<span class="line"><span>6) alt+c ：断开连接 /   ctrl + shfit +  R 重新连接</span></span>
<span class="line"><span></span></span>
<span class="line"><span>7) alt+1/2/3/4/5… ：切换会话窗口</span></span>
<span class="line"><span></span></span>
<span class="line"><span>8) 上下键：查找执行行过的命令,或者是history命令</span></span></code></pre></div><h2 id="_4-2-终端命令格式" tabindex="-1">4.2 终端命令格式 <a class="header-anchor" href="#_4-2-终端命令格式" aria-label="Permalink to &quot;4.2 终端命令格式&quot;">​</a></h2><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">command</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [-options] [parameter]</span></span></code></pre></div><p>说明:</p><ul><li><code>command</code> : 命令名, 相应功能的英文单词或单词的缩写</li><li><code>[-options]</code> : 选项, 可用来对命令进行控制, 也可以省略</li><li><code>parameter</code> : 传给命令的参数, 可以是 <strong>零个、一个 或者 多个</strong></li></ul><h2 id="_4-3-帮助命令" tabindex="-1">4.3 帮助命令 <a class="header-anchor" href="#_4-3-帮助命令" aria-label="Permalink to &quot;4.3 帮助命令&quot;">​</a></h2><p>因为一个命令有很多可选项, 死记硬背肯定不行, 所以需要借助手册查阅.</p><p><strong>1) -- help 帮助信息</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">command</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --help</span></span></code></pre></div><p>说明:</p><ul><li>显示 <code>command</code> 命令的帮助信息</li></ul><p>缺点: 虽然可以查询命令的帮助信息, 但是没有提供 翻页、搜索功能.</p><p><strong>2) man 手册</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">man</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span></code></pre></div><p>说明:</p><ul><li><p>查询<code>command</code>命令的使用手册</p><p><code>man</code> 时 <code>manual</code> 的缩写, 是Linux提供的一个<strong>手册,</strong> 包含了绝大部分的命令、函数的详细使用说明.</p></li></ul><p>使用 <code>man</code> 时的操作键:</p><table tabindex="0"><thead><tr><th>操作键</th><th>功能</th></tr></thead><tbody><tr><td>空格键</td><td>显示手册的下一屏</td></tr><tr><td>Enter键</td><td>一次滚动首页也得一行</td></tr><tr><td>b</td><td>回滚一屏</td></tr><tr><td>f</td><td>前滚一屏</td></tr><tr><td>q (quit)</td><td>退出</td></tr><tr><td>/word</td><td>搜索word字符串</td></tr><tr><td>n(next)</td><td>搜索下一个</td></tr><tr><td>N</td><td>搜索上一个</td></tr></tbody></table><p>提醒:</p><ul><li>现阶段只需要 <strong>知道</strong> 通过以下两种方式可以查询命令的帮助信息</li><li>先学习 <strong>常用命令</strong> 及 <strong>常用参数</strong> 的使用即可, 工作中如果遇到问题可以借助 <strong>网络搜索</strong></li></ul><h2 id="_4-4-其他常用命令" tabindex="-1">4.4 其他常用命令 <a class="header-anchor" href="#_4-4-其他常用命令" aria-label="Permalink to &quot;4.4 其他常用命令&quot;">​</a></h2><table tabindex="0"><thead><tr><th>序号</th><th>命令</th><th>对应英文</th><th>作用</th></tr></thead><tbody><tr><td>01</td><td>ls</td><td>list</td><td>查看当前目录下的内容</td></tr><tr><td>02</td><td>pwd</td><td>print working derectory</td><td>查看当前所在文件夹</td></tr><tr><td>03</td><td>cd [目录名]</td><td>change directory</td><td>切换文件夹</td></tr><tr><td>04</td><td>touch [文件名]</td><td>touch</td><td>如果文件不存在, 新建文件</td></tr><tr><td>05</td><td>mkdir [目录名]</td><td>make directory</td><td>创建目录</td></tr><tr><td>06</td><td>rm [文件名]</td><td>remove</td><td>删除指定的文件名</td></tr><tr><td>07</td><td>clear</td><td>clear</td><td>清屏</td></tr></tbody></table><h2 id="_4-5-目录操作命令" tabindex="-1">4.5 目录操作命令 <a class="header-anchor" href="#_4-5-目录操作命令" aria-label="Permalink to &quot;4.5 目录操作命令&quot;">​</a></h2><p>Linux中并没有文件夹的概念，应该叫目录。</p><h3 id="_4-5-1-切换目录" tabindex="-1">4.5.1 切换目录 <a class="header-anchor" href="#_4-5-1-切换目录" aria-label="Permalink to &quot;4.5.1 切换目录&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cd(change directory) 功能: 切换目录</span></span>
<span class="line"><span>pwd(print work directory)	功能: 显示当前工作目录</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps930A.tmp.jpg" alt="img"></p><h3 id="_4-5-2-练习" tabindex="-1">4.5.2 练习 <a class="header-anchor" href="#_4-5-2-练习" aria-label="Permalink to &quot;4.5.2 练习&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 查看当前所在目录</span></span>
<span class="line"><span>2 切换到 /usr/local(绝对路径)</span></span>
<span class="line"><span>3 切换到 上一级 /usr</span></span>
<span class="line"><span>4 切换到 /usr/tmp (相对路径)</span></span>
<span class="line"><span>5 切换回 /usr/local</span></span>
<span class="line"><span>6 后退到上一次所在目录</span></span></code></pre></div><p>答案</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">pwd</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/local</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ..</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tmp</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/local</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -</span></span></code></pre></div><h2 id="_4-6-查看目录内容" tabindex="-1">4.6 查看目录内容 <a class="header-anchor" href="#_4-6-查看目录内容" aria-label="Permalink to &quot;4.6 查看目录内容&quot;">​</a></h2><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>ls(list)		功能: 列出目录内容</span></span>
<span class="line"><span>	a(all)		功能: 所有</span></span>
<span class="line"><span>	h(human)	功能: 人性化的显示(单位: K,G等)</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1532429846711.png" alt="1532429846711"></p><h3 id="_4-6-1-ls练习" tabindex="-1">4.6.1 ls练习 <a class="header-anchor" href="#_4-6-1-ls练习" aria-label="Permalink to &quot;4.6.1 ls练习&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 查看 /usr内容</span></span>
<span class="line"><span>2 查看所有 /usr内容(既包含隐藏,也包含非隐藏)</span></span>
<span class="line"><span>3 查看 /usr详细内容</span></span>
<span class="line"><span>4 简化 查看 /usr详细内容</span></span>
<span class="line"><span>5 易懂简化版 查看 /usr详细内容</span></span></code></pre></div><p>答案</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost /]# ls</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  boot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  etc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  home</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  lib</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  lib64</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  media</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  mnt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  opt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  proc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  run</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  sbin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  srv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  sys</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  tmp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  usr</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  var</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost /]# ls -a</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  ..</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  bin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  boot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  etc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  home</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  lib</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  lib64</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  media</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  mnt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  opt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  proc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  run</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  sbin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  srv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  sys</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  tmp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  usr</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  var</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost /]# ls -l</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/bin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   5</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4096</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3240</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  75</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8192</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> etc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 02:56</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> home</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    9</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib64</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib64</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> media</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mnt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> opt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 112</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> proc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-x---.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  151</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 22:37</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  23</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  680</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> run</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sbin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/sbin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> srv</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sys</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxrwxrwt.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  11</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4096</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 03:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tmp</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  155</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  267</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> var</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost /]# ll</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 20</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/bin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   5</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4096</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3240</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  75</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8192</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> etc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 02:56</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> home</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    9</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib64</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib64</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> media</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mnt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> opt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 112</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> proc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-x---.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  151</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 22:37</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  23</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  680</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> run</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sbin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/sbin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> srv</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sys</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxrwxrwt.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  11</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4096</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 03:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tmp</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  155</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  267</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> var</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost /]# ls -lh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 20K</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/bin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   5</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 4.0K</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> boot</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 3.2K</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  75</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8.0K</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> etc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 02:56</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> home</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    9</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lib64</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/lib64</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> media</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mnt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> opt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 112</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> proc</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-x---.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  151</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 22:37</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  23</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  680</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:55</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> run</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lrwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    8</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sbin</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> -</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr/sbin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">   2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 11月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2016</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> srv</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dr-xr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  14</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01:42</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> sys</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxrwxrwt.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  11</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 4.0K</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  16</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 03:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tmp</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  155</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:05</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> usr</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">drwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  267</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  13</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:20</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> var</span></span></code></pre></div><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>linux 如何树结构显示某文件夹下的所有文件（包括子文件夹 ）？ </span></span>
<span class="line"><span>ls -R</span></span></code></pre></div><h2 id="_4-7-创建文件" tabindex="-1">4.7 创建文件 <a class="header-anchor" href="#_4-7-创建文件" aria-label="Permalink to &quot;4.7 创建文件&quot;">​</a></h2><p>通过 <code>touch </code> 命令 创建文件</p><p>第一步: 创建一个空白文件</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">touch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不存在的文件</span></span></code></pre></div><p>第二步: 修改文件的末次访问时间</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">touch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 存在的文件</span></span></code></pre></div><p>2）案例例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# touch test.txt</span></span></code></pre></div><h2 id="_4-8-创建目录命令" tabindex="-1">4.8 创建目录命令 <a class="header-anchor" href="#_4-8-创建目录命令" aria-label="Permalink to &quot;4.8 创建目录命令&quot;">​</a></h2><p>通过 <code>mkdir</code> 命令 创建目录</p><p>基本语法</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>mkdir [-p] 要创建的目录</span></span></code></pre></div><table tabindex="0"><thead><tr><th>选项</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>-p</td><td>parent</td><td>可以递归创建目录</td></tr></tbody></table><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# mkdir test</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# mkdir -p test/test1</span></span></code></pre></div><p><strong>注意</strong></p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>通过 mkdir -p 目录名 命令 创建目录</span></span>
<span class="line"><span>注意: 新建目录的名称 不能与当前目录中 已有的目录或文件同名</span></span></code></pre></div><h2 id="_4-9-rmdir-删除一个空的目录" tabindex="-1">4.9 rmdir 删除一个空的目录 <a class="header-anchor" href="#_4-9-rmdir-删除一个空的目录" aria-label="Permalink to &quot;4.9 rmdir 删除一个空的目录&quot;">​</a></h2><p>基本语法： rmdir 要删除的空目录，remove 即移除</p><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# mkdir test2</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# rmdir test2</span></span></code></pre></div><p>注意:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>如果该目录中存在文件或其他目录是该命令是不能删除的.</span></span></code></pre></div><h2 id="_4-10-touch创建文件和rm-删除文件" tabindex="-1">4.10 touch创建文件和rm 删除文件 <a class="header-anchor" href="#_4-10-touch创建文件和rm-删除文件" aria-label="Permalink to &quot;4.10 touch创建文件和rm 删除文件&quot;">​</a></h2><blockquote><p>1)创建文件的命令</p></blockquote><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">touch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   文件名称</span></span></code></pre></div><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">注意事项:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">touch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件名1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ..</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    可以创建多个文件</span></span></code></pre></div><blockquote><ol start="2"><li>删除命令</li></ol></blockquote><p>语法</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>rm [-参数] 文件/目录 （功能描述：递归删除目录中所有内容）慎用</span></span></code></pre></div><p>通过 <code>rm -rf 文件/目录</code> 命令实现删除 文件和目录的功能, <code>rm</code> 对应的英文是 <code>remove</code> 含义: 删除</p><table tabindex="0"><thead><tr><th>参数</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>-f</td><td>force (强制)</td><td>强制删除,忽略不存在的文件, 无需提示</td></tr><tr><td>-r</td><td>recursive (递归)</td><td>递归地删除目录下的内容, <strong>删除文件夹</strong> 时必须加此参数</td></tr></tbody></table><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps930C.tmp.jpg" alt="img"></p><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1）删除空目录</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# rmdir test1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2）递归删除目录中所有内容</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# rm -rf test2</span></span></code></pre></div><h2 id="_4-11-cp-复制拷贝命令" tabindex="-1">4.11 cp 复制拷贝命令 <a class="header-anchor" href="#_4-11-cp-复制拷贝命令" aria-label="Permalink to &quot;4.11 cp 复制拷贝命令&quot;">​</a></h2><p>通过 <code>cp</code> 实现复制将指定的 文件 或 目录 复制到 两一个 文件 或 目录中</p><p>基本语法:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>（1）cp source dest （功能描述：复制source文件到dest）</span></span>
<span class="line"><span>（2）cp -r sourceFolder targetFolder （功能描述：递归复制整个文件夹）</span></span></code></pre></div><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>作用</th></tr></thead><tbody><tr><td>-r</td><td>recursive (递归)</td><td>递归复制目标目录的内容</td></tr></tbody></table><p>案例:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）复制文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 opt]# cp test.txt test1.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）递归复制整个文件夹</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 opt]# cp -r abc /tmp</span></span></code></pre></div><h2 id="_4-12-mv-move" tabindex="-1">4.12 mv (move) <a class="header-anchor" href="#_4-12-mv-move" aria-label="Permalink to &quot;4.12 mv (move)&quot;">​</a></h2><p>通过<code>mv</code> 命令可以用来 移动 文件 或 目录, 也可以给 文件或目录重命名</p><p>基本语法</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）mv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> oldNameFile</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> newNameFile</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：重命名）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）mv</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /temp/movefile</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /targetFolder</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：递归移动文件）</span></span></code></pre></div><p>2）案例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1）重命名</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# mv file1 file11 （把file1文件夹改名为file11）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2）移动文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# mv file11 test （把file11文件夹放到test文件夹内</span></span></code></pre></div><h2 id="_4-13-cat-查看文件内容" tabindex="-1">4.13 cat 查看文件内容 <a class="header-anchor" href="#_4-13-cat-查看文件内容" aria-label="Permalink to &quot;4.13 cat 查看文件内容&quot;">​</a></h2><p>查看文件内容，从第一行行开始显示。 1）基本语法</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cat [选项] 要查看的文件</span></span></code></pre></div><ol start="2"><li>选项</li></ol><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>-b ：列出行号，仅针对非空白行做行号显示，空白行不标行号！</span></span>
<span class="line"><span>-E ：将结尾的断行行字节 $ 显示出来；</span></span>
<span class="line"><span>-n ：列出行号，连同空白行也会有行号，与 -b 的选项不不同；</span></span>
<span class="line"><span>-T ：将 [tab] 按键以 ^I 显示出来；</span></span>
<span class="line"><span>-v ：列出一些看不出来的特殊字符</span></span>
<span class="line"><span>-A ：相当于 -vET 的整合选项，可列列出一些特殊字符而不不是空白而已；</span></span></code></pre></div><ol start="3"><li>案例</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看内容</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat abc.txt </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">babbaba</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">abababab</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ababbabaZZ</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看添加-A</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -A abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">babbaba$</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">abababab$</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ababbabaZZ$</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看添加-b</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -b abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  babbaba</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  abababab</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  ababbabaZZ</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">     </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看添加-E</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -E abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">babbaba$</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">abababab$</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ababbabaZZ$</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看内容添加-n</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -n abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  babbaba</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  abababab</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">     3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  ababbabaZZ</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">     </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看内容添加-T</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -T abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">babbaba</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">abababab</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ababbabaZZ</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">查看内容添加-v</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@localhost usr]# cat -v abc.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">babbaba</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">abababab</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ababbabaZZ</span></span></code></pre></div><h2 id="_4-14-more-查看文件内容" tabindex="-1">4.14 more 查看文件内容 <a class="header-anchor" href="#_4-14-more-查看文件内容" aria-label="Permalink to &quot;4.14 more 查看文件内容&quot;">​</a></h2><p>查看文件内容，一页一页的显示文件内容。 1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>more 要查看的文件</span></span></code></pre></div><p>2）功能使用说明</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>空格键 (space)：代表向下翻一页；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Enter:代表向下翻『一行』；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>q代表立刻离开 more ，不再显示该文件内容。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Ctrl+F 向下滚动一屏</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Ctrl+B 返回上一屏</span></span>
<span class="line"><span></span></span>
<span class="line"><span>= 输出当前行的行号</span></span></code></pre></div><p>3）案例</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 test1]# more test1.java</span></span></code></pre></div><h2 id="_4-15-less-查看文件内容" tabindex="-1">4.15 less 查看文件内容 <a class="header-anchor" href="#_4-15-less-查看文件内容" aria-label="Permalink to &quot;4.15 less 查看文件内容&quot;">​</a></h2><p>less 的作用与 more 十分相似，都可以用来浏览文字档案的内容，不同的是 less 允许使用[pageup] [pagedown]往回滚动。 1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>less 要查看的文件</span></span></code></pre></div><p>2）功能使用说明</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>空格键 ：向下翻动一页；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[pagedown]：向下翻动一页；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[pageup] ：向上翻动一页；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>/字符串 ：向下搜寻『字符串』的功能；n：向下查找；N：向上查找；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>q ：离开 less 这个程序；</span></span></code></pre></div><p>3）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test1]# less test1.java</span></span></code></pre></div><h2 id="_4-16-head查看文件内容" tabindex="-1">4.16 head查看文件内容 <a class="header-anchor" href="#_4-16-head查看文件内容" aria-label="Permalink to &quot;4.16 head查看文件内容&quot;">​</a></h2><p>查看文件内容，只看头几行，优点：对于大文件不必都加载，只显示头几行行即可。</p><blockquote><ol><li>基本语法</li></ol></blockquote><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">head</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件名　　　　</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">	：查看前10行</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">head</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -n</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件名　　</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   ：查看文件的前3行</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">head</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件名　　</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   ：查看文件的前3个字符</span></span></code></pre></div><h2 id="_4-17-tail-查看文件内容" tabindex="-1">4.17 tail 查看文件内容 <a class="header-anchor" href="#_4-17-tail-查看文件内容" aria-label="Permalink to &quot;4.17 tail 查看文件内容&quot;">​</a></h2><p>查看文件内容，只看尾巴几行行，优点：可以查看⽂文件实时追加的内容。 1）基本语法</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -n</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：查看文件头（从末尾开始数）10行行内容，10可以是任意行行数）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：实时追踪该文档的所有更更新）</span></span></code></pre></div><p>2）案例</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 查看文件后10行内容</span></span>
<span class="line"><span>2 动态追踪文件内容</span></span>
<span class="line"><span>3 动态追踪 最后10行内容 且 退出</span></span></code></pre></div><p>答案</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>tail -10 文件名</span></span>
<span class="line"><span>tail -f 文件名</span></span>
<span class="line"><span>tail -10f 文件名 (ctrl + c 是退出)</span></span></code></pre></div><h2 id="_4-18-组合命令" tabindex="-1">4.18 组合命令 <a class="header-anchor" href="#_4-18-组合命令" aria-label="Permalink to &quot;4.18 组合命令&quot;">​</a></h2><p>Linux中的命令组合后，可以产生神奇的效果!</p><p>append 追加</p><p>replace 替换,覆盖</p><h3 id="_4-18-1-重定向输出-和" tabindex="-1">4.18.1 重定向输出&gt;和&gt;&gt; <a class="header-anchor" href="#_4-18-1-重定向输出-和" aria-label="Permalink to &quot;4.18.1 重定向输出&gt;和&gt;&gt;&quot;">​</a></h3><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps9323.tmp.jpg" alt="img"></p><p>echo 控制台输出的内容 (类似sout)</p><p>需求:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 删除 /usr/tmp/目录下的所有内容</span></span>
<span class="line"><span>2 增加 1.txt文件, 内容: 文本1</span></span>
<span class="line"><span>3 增加 2.txt文件, 内容: 文本2</span></span>
<span class="line"><span>4 将2.txt内容 复制粘贴到 3.txt</span></span>
<span class="line"><span>5 将1.txt内容 复制粘贴到 3.txt(缺点: 产生替换效果)</span></span>
<span class="line"><span>6 将2.txt内容 复制追加粘贴到 3.txt中</span></span>
<span class="line"><span>7 将ifconfig内容 追加到 3.txt中</span></span></code></pre></div><p>答案:</p><p>1 删除 /usr/tmp/目录下的所有内容</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# rm -rf </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span></span></code></pre></div><p>2 增加 1.txt文件, 内容: hello</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# touch 1.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# echo hello </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 1.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span></span></code></pre></div><p>3 增加 2.txt文件, 内容: world</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# touch 2.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1.txt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  2.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# echo world </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 2.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 2.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">world</span></span></code></pre></div><p>4 将2.txt内容 复制粘贴到 3.txt</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">root</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">@spark01 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">tmp</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># touch 3.txt &amp;&amp; ls</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">txt  </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">txt  </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">root</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">@spark01 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">tmp</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># cat 2.txt &gt; 3.txt &amp;&amp; cat 3.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">world</span></span></code></pre></div><p>5 将1.txt内容 复制粘贴到 3.txt(缺点: 产生替换效果)</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# cat 1.txt </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 3.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 3.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span></span></code></pre></div><p>6 将2.txt内容 复制追加粘贴到 3.txt中</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# cat 2.txt </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 3.txt &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 3.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">world</span></span></code></pre></div><p>7 将ifconfig指令内容 追加到 3.txt中</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# ifconfig </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 3.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@spark01 tmp]# cat 3.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">world</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">eth0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">      Link</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> encap:Ethernet</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  HWaddr</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 00:0C:29:0E:3F:05</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          inet</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> addr:192.168.220.200</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  Bcast:192.168.220.255</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  Mask:255.255.255.0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          inet6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> addr:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> fe80::20c:29ff:fe0e:3f05/64</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Scope:Link</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          UP</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> BROADCAST</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> RUNNING</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> MULTICAST</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  MTU:1500</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  Metric:1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          RX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> packets:12903</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> errors:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dropped:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> overruns:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> frame:0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          TX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> packets:10765</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> errors:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dropped:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> overruns:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> carrier:0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          collisions:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> txqueuelen:1000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          RX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bytes:1189753</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (1.1 </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">MiB</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)  TX bytes:3324044 (</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">3.1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> MiB</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          Interrupt:19</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Base</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> address:0x2000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">lo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Link</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> encap:Local</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Loopback</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          inet</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> addr:127.0.0.1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  Mask:255.0.0.0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          inet6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> addr:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ::1/128</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Scope:Host</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          UP</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> LOOPBACK</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> RUNNING</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  MTU:16436</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  Metric:1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          RX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> packets:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> errors:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dropped:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> overruns:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> frame:0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          TX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> packets:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> errors:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dropped:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> overruns:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> carrier:0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          collisions:0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> txqueuelen:0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">          RX</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bytes:0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (0.0 </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)  TX bytes:0 (</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">0.0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><h3 id="_4-18-2-管道" tabindex="-1">4.18.2 管道 “|” <a class="header-anchor" href="#_4-18-2-管道" aria-label="Permalink to &quot;4.18.2 管道 “|”&quot;">​</a></h3><p><code>管道符号| 的作用是: 将一个命令的输出作为另一个命令的输入.</code></p><p>配合使用的命令</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>ps(Process Status) 	进程状态  ps -ef</span></span>
<span class="line"><span>grep(Global Regular Expression Print) 全局正则表达式版本(搜索)</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps9334.tmp.jpg" alt="img"></p><p>需求:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 分页查询 ls的帮助信息(回车键 下一行, 空格键 下一页, ctrl +c 退出)</span></span>
<span class="line"><span>2 查询ls帮助信息中包含&#39;递归&#39;的指令</span></span></code></pre></div><p>答案:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --help</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> more</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --help</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> grep</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;递归&#39;</span></span></code></pre></div><h3 id="_4-18-3-逻辑控制" tabindex="-1">4.18.3 逻辑控制&amp;&amp; <a class="header-anchor" href="#_4-18-3-逻辑控制" aria-label="Permalink to &quot;4.18.3 逻辑控制&amp;&amp;&quot;">​</a></h3><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps9335.tmp.jpg" alt="img"></p><p>因为 启动软件通常不会打印启动的日志信息, 所以需要再打开对应的日志信息查看.</p><p>分:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -100f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> catalina.out</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./startup.sh</span></span></code></pre></div><p>使用合并指令:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./startup.sh</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -100f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> catalina.out</span></span></code></pre></div><p>缺点: 比较麻烦. 解决: 使用&amp;&amp;指令就可以一步到位</p><p>这个经常把一些命令组合使用，比如我们在启动tomcat后，再用tail命令查看日志。如果启动失败，则不查看</p><p>./startup.sh &amp;&amp; tail -50f ../logs/catalina.out</p><p>需求:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 打印1.txt内容 且 打印2.txt内容</span></span>
<span class="line"><span>2 打印100.txt内容 且 打印2.txt内容(没有)</span></span>
<span class="line"><span>3 启动tomcat 且 打印日志信息</span></span></code></pre></div><p>答案:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1.txt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 2.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 100.txt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat.2.txt</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./startup.sh</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -50f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ../logs/catalina.out</span></span></code></pre></div><h2 id="_4-19-history查看所敲命令历史" tabindex="-1">4.19 history查看所敲命令历史 <a class="header-anchor" href="#_4-19-history查看所敲命令历史" aria-label="Permalink to &quot;4.19 history查看所敲命令历史&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">history</span></span></code></pre></div><p>2）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# history</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592660053848.png" alt="1592660053848"></p><h1 id="第5章-打包和解包命令" tabindex="-1">第5章 打包和解包命令 <a class="header-anchor" href="#第5章-打包和解包命令" aria-label="Permalink to &quot;第5章 打包和解包命令&quot;">​</a></h1><h2 id="_5-1-打tar包" tabindex="-1">5.1 打tar包 <a class="header-anchor" href="#_5-1-打tar包" aria-label="Permalink to &quot;5.1 打tar包&quot;">​</a></h2><ul><li><strong>类似将 冬天的衣服 放到 袋</strong></li><li>打包之后的大文件 需要以 <code>.tar</code> 结尾.</li></ul><p><code>tar</code> <strong>打包</strong>命令格式</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 将 一系列文件 打包成 一个大文件</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -cvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包名.tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 被打包的目录</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -cvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包名.tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 被打包的文件1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 被打包的文件2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 被打包的文件3</span></span></code></pre></div><p><code>tar</code> 选项说明</p><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>c</td><td>create</td><td>生成档案文件, 创建打包文件</td></tr><tr><td>v</td><td>verbosely(啰嗦的)</td><td>像 &#39;唐僧&#39; 一样报告进度</td></tr><tr><td>f</td><td>file</td><td>指定档案的文件名称, f后面一定是 <code>.tar</code> 文件, 所以必须放到左后</td></tr></tbody></table><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>练习1: 将1.txt、2.txt、3.txt 打包成 123.tar文件</span></span>
<span class="line"><span></span></span>
<span class="line"><span>练习2: 将有内容的aaa目录 打包成 aaa.tar 文件</span></span></code></pre></div><h2 id="_5-2-解tar包" tabindex="-1">5.2 解tar包 <a class="header-anchor" href="#_5-2-解tar包" aria-label="Permalink to &quot;5.2 解tar包&quot;">​</a></h2><ul><li><strong>类似将 冬天的衣服 从 袋子里取出来</strong></li></ul><p><code>tar</code> <strong>解包</strong>命令格式</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 将一个打包后的 分解成 一系列小文件, 分解位置为 当前目录</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -xvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包名.tar</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 将一个打包后的 分解成 一系列小文件, 分解位置为 指定目录</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -xvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包名.tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -C</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解包路径位置</span></span></code></pre></div><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>x</td><td>extract (提取)</td><td>解包</td></tr><tr><td>C (大写C)</td><td>directory (目录)</td><td>默认保存到当前目录, 通过<code>-C</code> 更改解压目录, 注意: 解压目录必须存在</td></tr></tbody></table><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习1:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 123.tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解压到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 当前目录中</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习2:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aaa.tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解包到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /export/test/a1/b1/c1/</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 目录中</span></span></code></pre></div><p><strong>小结</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">打包:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -cvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包之后的文件名.tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   被打包的目录或文件名</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">解包:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -xvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包之后的文件名.tar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  [ </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">-C</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  指定解包位置</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span></span></code></pre></div><h2 id="_5-3-gzip格式-压缩-和-解压缩" tabindex="-1">5.3 gzip格式 压缩 和 解压缩 <a class="header-anchor" href="#_5-3-gzip格式-压缩-和-解压缩" aria-label="Permalink to &quot;5.3 gzip格式 压缩 和 解压缩&quot;">​</a></h2><ul><li><strong>打包</strong> 和 <strong>压缩</strong> 是两件事</li><li><strong>类似与 先将冬天衣服放到压缩袋, 再抽取里面的空气</strong></li><li>在 <code>Linux</code> 中, 最常用的压缩文件格式是 <code>xxx.tar.gz</code></li><li>在 <code>tar</code> 命令中有一个选项 -z 可以调用 <code>gzip</code> , 从而可以方便的实现压缩和解压缩的功能</li></ul><p>命令格式如下</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 压缩文件</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -zcvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包压缩文件名.tar.gz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 被压缩的文件/目录</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 解压缩文件</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -zxvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包文件.tar.gz</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 解压缩到指定路径</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -zxvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包文件.tar.gz</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -C</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 目录路径</span></span></code></pre></div><p><code>tar</code> 的选项说明</p><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>z</td><td>gzip</td><td>使用gzip压缩和解压缩</td></tr><tr><td>j</td><td>bzip2</td><td>使用bzip2压缩和解压缩</td></tr></tbody></table><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习1:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将1.txt、2.txt、3.txt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包压缩成</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 123.tar.gz文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gzip压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习2:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将有内容的aaa目录</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包成</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aaa.tar.gz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gzip压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习3:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 123.tar.gz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解压到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 当前目录中</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gzip压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习4:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aaa.tar.gz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解包到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /export/bbb</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 目录中</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gzip压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><h2 id="_5-4-bzip2-格式-压缩-和-解压缩" tabindex="-1">5.4 bzip2 格式 压缩 和 解压缩 <a class="header-anchor" href="#_5-4-bzip2-格式-压缩-和-解压缩" aria-label="Permalink to &quot;5.4 bzip2 格式 压缩 和 解压缩&quot;">​</a></h2><ul><li><code>bzip</code> 是压缩的第二种方式</li><li><strong>类似与 先将冬天衣服放到压缩袋, 再抽取里面的空气</strong></li><li>在 <code>Linux</code> 中, bzip2 压缩文件格式是 <code>xxx.tar.bz2</code></li><li>在 <code>tar</code> 命令中有一个选项 -j 可以调用 <code>bzip2</code> , 从而可以方便的实现压缩和解压缩的功能</li></ul><p>命令格式如下</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span># 压缩文件</span></span>
<span class="line"><span>tar -jcvf 打包压缩文件名.tar.bz2 被压缩的文件/目录</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 解压缩文件 (绩效潍坊)</span></span>
<span class="line"><span>tar -jxvf 打包文件.tar.bz2</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 解压缩到指定路径</span></span>
<span class="line"><span>tar -jxvf 打包文件.tar.bz2 -C 目录路径</span></span></code></pre></div><blockquote><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">注意事项:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 如果报错tar</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (child): bzip2：无法 exec: 没有那个文件或目录 </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">要安装bzip2的包</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">yum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bzip2</span></span></code></pre></div></blockquote><p><code>tar</code> 的选项说明</p><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td>z</td><td>gzip</td><td>使用gzip压缩和解压缩</td></tr><tr><td>j</td><td>bzip2</td><td>使用bzip2压缩和解压缩</td></tr></tbody></table><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习1:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将1.txt、2.txt、3.txt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包压缩成</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 123.tar.bz2文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bzip2压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习2:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将有内容的aaa目录</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包成</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aaa.tar.bz2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bzip2压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习3:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 123.tar.bz2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解压到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 当前目录中</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bzip2压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">练习4:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aaa.tar.bz2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 解包到</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /export/bbb</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 目录中</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bzip2压缩格式</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p>小结</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">打包压缩:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -jcvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包之后的文件名.tar.bz2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   被打包压缩的目录或文件名</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">解包解压缩:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -jxvf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 打包之后的文件名.tar.bz2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  [ </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">-C</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  指定解包位置</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span></span></code></pre></div><h1 id="第6章-时间日期" tabindex="-1">第6章 时间日期 <a class="header-anchor" href="#第6章-时间日期" aria-label="Permalink to &quot;第6章 时间日期&quot;">​</a></h1><h2 id="_6-1-date-显示当前时间" tabindex="-1">6.1 date 显示当前时间 <a class="header-anchor" href="#_6-1-date-显示当前时间" aria-label="Permalink to &quot;6.1 date 显示当前时间&quot;">​</a></h2><p>基本语法：注意命令与参数之间有空格</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示当前时间）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +%Y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示当前年年份）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（3）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +%m</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示当前月份）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（4）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示当前是哪一天）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（5）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +%Y%m%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> …</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示当前年年月日各种格式</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ）</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（6）date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;+%Y-%m-%d %H:%M:%S&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 或者单引号也可以</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示年年⽉月⽇日时分秒）</span></span></code></pre></div><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# date</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# date +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;%Y-%m-%d&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">注意date后面有个空格再加</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# date </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;+%Y-%m-%d %H:%M:%S&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">注意date后面有个空格再加</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ；注意%d空格%H</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p>显示的是字符串串描述的时间，不是当前时间。</p><h2 id="_6-2-date显示非当前时间" tabindex="-1">6.2 date显示非当前时间 <a class="header-anchor" href="#_6-2-date显示非当前时间" aria-label="Permalink to &quot;6.2 date显示非当前时间&quot;">​</a></h2><p>显示的是字符串串描述的时间，不是当前时间。 1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）date</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;1 days ago&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示前一天日期）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）date</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> yesterday</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +&quot;%Y-%m-%d&quot;（同上）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（3）date</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> next-day</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +&quot;%Y-%m-%d&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示明天日期）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（4）date</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;next monday&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：显示下周一时间）</span></span></code></pre></div><p>2）案例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# date -d </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;1 days ago&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2020年年</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 04月</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01日</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 星期三</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 21:07:22</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> CST</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# date -d </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;next monday&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2020年年</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 04月</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 01日</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 星期三</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 00:00:00</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> CST</span></span></code></pre></div><h2 id="_6-3-设置系统时间" tabindex="-1">6.3 设置系统时间 <a class="header-anchor" href="#_6-3-设置系统时间" aria-label="Permalink to &quot;6.3 设置系统时间&quot;">​</a></h2><p>1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>date -s 字符串时间</span></span></code></pre></div><p>2）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@hadoop106 /]# date -s </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;2020-06-20 20:52:18&quot;</span></span></code></pre></div><h2 id="_6-4-cal查看日历" tabindex="-1">6.4 cal查看日历 <a class="header-anchor" href="#_6-4-cal查看日历" aria-label="Permalink to &quot;6.4 cal查看日历&quot;">​</a></h2><p>1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cal [选项] （功能描述：不加选项，显示本月日历）</span></span></code></pre></div><p>选项：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>-3 ，显示系统前一个月，当前月，下一个月的日历</span></span>
<span class="line"><span></span></span>
<span class="line"><span>具体某一年年，显示这一年年的日历。</span></span></code></pre></div><p>​ 2）案例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# cal</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# cal -3</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 /]# cal 2020</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592706333520.png" alt="1592706333520"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592706342714.png" alt="1592706342714"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592706365021.png" alt="1592706356222"></p><h1 id="第七章-搜索查找" tabindex="-1">第七章 搜索查找 <a class="header-anchor" href="#第七章-搜索查找" aria-label="Permalink to &quot;第七章 搜索查找&quot;">​</a></h1><h2 id="_7-1-find-查找文件或者目录" tabindex="-1">7.1 find 查找文件或者目录 <a class="header-anchor" href="#_7-1-find-查找文件或者目录" aria-label="Permalink to &quot;7.1 find 查找文件或者目录&quot;">​</a></h2><blockquote><p>find命令是根据<strong>文件的属性</strong>进行查找，如文件名，文件大小，所有者，所属组，是否为空，访问时间，修改时间等。</p></blockquote><p><strong>基本格式：<code>find path [options]</code></strong></p><p><strong>1.按照文件名查找</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -name</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> yum.conf　　#在/etc目录下文件yum.conf</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -name</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;yum&#39;　　#使用通配符</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">0或者任意多个</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">。表示在/etc目录下查找文件名中含有字符串‘yum’的文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> .</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -name</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;yum*&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 　　#表示当前目录下查找文件名开头是字符串‘yum’的文件</span></span></code></pre></div><p><strong>2.按照文件特征查找</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -atime</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -2　　</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 查找在系统中最后48小时访问的文件 (Access Time，文件读取访问时间)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -empty</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 　　   # 查找在系统中为空的文件或者文件夹</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -group</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> susan</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 　　#</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 查找在系统中属于group为susan的文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -mtime</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 　　#查找在系统中最后24小时里修改过的文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (modify </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">time</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -user</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> susan</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 　　#查找在系统中属于susan这个用户的文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -size</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +10000c　　#查找出大于10000字节的文件</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">c:字节，w:双字，k:KB，M:MB，G:GB</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -size</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -1000k</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 　　#查找出小于1000KB的文件</span></span></code></pre></div><p></p><p><strong>3.使用混合查找方式查找文件</strong></p><p><strong>参数有： ！，-and(-)，-or(-o)。</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /tmp</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -size</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +10c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -and</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -mtime</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +2</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 　 #在/tmp目录下查找大于10字节并在2天前修改的文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -user</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -or</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -user</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> susan</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 　　	#在/目录下查找用户是root或者susan的文件文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">find</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /tmp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -user</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> susan　　</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">			#在/tmp目录中查找所有不属于susan用户的文件</span></span></code></pre></div><h2 id="_7-2-grep-过滤查找" tabindex="-1">7.2 grep 过滤查找 <a class="header-anchor" href="#_7-2-grep-过滤查找" aria-label="Permalink to &quot;7.2 grep 过滤查找&quot;">​</a></h2><blockquote><p>grep是根据<strong>文件的内容进行</strong>查找，会对文件的每一行按照给定的模式(patter)进行匹配查找。</p></blockquote><p><strong>基本格式：grep [options] 范围</strong></p><p><strong>1.主要参数</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[options]主要参数：</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">　　　　－c：只输出匹配行的计数。</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">　　　　－i：不区分大小写</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">　　　　－n：显示匹配行及行号。</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">　　　　 -w:显示整个单词</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">　　　　 -r:递归查询</span></span></code></pre></div><p>实例练习:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)在applicationContext.xml文件中查找name </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)查找name统计行号</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)统计jdbc的个数</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)查找dataSource 并忽略大小写</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)查找mapper单词</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)递归查询/usr目录下 含有name的字段</span></span></code></pre></div><h1 id="第8章-vi编辑器" tabindex="-1">第8章 vi编辑器 <a class="header-anchor" href="#第8章-vi编辑器" aria-label="Permalink to &quot;第8章 vi编辑器&quot;">​</a></h1><ul><li>在Linux下一般使用vi编辑器来编辑文件。</li><li>vi既可以查看文件也可以编辑文件。</li><li>而vim是vi的升级版本，具备更多的功能.</li><li>vi如果目标文件不存在，会创建新的文件。但是如果新文件没做编辑，退出后还会消失。</li></ul><h2 id="_8-1-vi的三种模式介绍" tabindex="-1">8.1 vi的三种模式介绍 <a class="header-anchor" href="#_8-1-vi的三种模式介绍" aria-label="Permalink to &quot;8.1 vi的三种模式介绍&quot;">​</a></h2><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/wps9322.tmp.jpg" alt="img"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1536839487082.png" alt="1536839487082"></p><p>编辑模式(插入模式)：对文本进行输入和修改</p><p>底行模式：退出vim或者查找、替换功能</p><p>命令模式(一般模式)：通过快捷命令操作数据，打开vi默认就是命令模式</p><blockquote><p>如果vim命令不能使用需要安装:</p><p>yum -y install vim-enhanced</p></blockquote><h2 id="_8-2-编辑模式" tabindex="-1">8.2 编辑模式 <a class="header-anchor" href="#_8-2-编辑模式" aria-label="Permalink to &quot;8.2 编辑模式&quot;">​</a></h2><p>命令模式按下：i、o、a进入编辑模式：</p><p>i：光标不动</p><p>o：另起一行</p><p>a：光标到下一个字符</p><p>按ESC退出编辑模式,进入命令模式</p><h2 id="_8-3-底行模式" tabindex="-1">8.3 底行模式 <a class="header-anchor" href="#_8-3-底行模式" aria-label="Permalink to &quot;8.3 底行模式&quot;">​</a></h2><p>命令模式下，按‘：’或者‘/’进入底行模式，可以输入命令</p><p>1）退出vim:(重点重点重点)</p><p>:q 未编辑时退出vim</p><p>:q! 编辑后，退出并且不保存</p><p>:wq 编辑后，退出且保存</p><p>:x 编译后保存</p><p>2）撤销上次操作(扩展---一般模式下)</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">u</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 			撤销上一次操作</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ctrl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> z</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> windows操作</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ctrl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> r</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 		恢复上一次被撤销的操作</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (ctrl </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> windows操作</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p>3）设置行号(了解) 底行模式</p><p>:set nu 显示行号</p><p>:set nonu 不显示行号</p><p>4）替换文本(了解)</p><p>😒/old/new/ 用new替换old，替换当前行的第一个匹配</p><p>😒/old/new/g 用new替换old，替换当前行的所有匹配</p><p>:%s/old/new/ 用new替换old，替换所有行的第一个匹配</p><p>:%s/old/new/g 用new替换old，替换整个文件的所有匹配</p><p>5）查找 (一般模式)</p><p>/文本 搜索指定文本，高亮显示，按n显示下一个，按N显示前一个</p><p>:整数 快捷跳转到指定行</p><h2 id="_8-4-命令模式-一般模式" tabindex="-1">8.4 命令模式(一般模式) <a class="header-anchor" href="#_8-4-命令模式-一般模式" aria-label="Permalink to &quot;8.4 命令模式(一般模式)&quot;">​</a></h2><p>p(pause) 将之前dd或yy的数据粘贴到光标位置</p><p>yy 复制光标所在行</p><p>5yy 复制光标及下面共5行</p><p>dd 剪切当前行</p><p>5dd 剪切光标及下面共5行</p><h1 id="第9章-用户及组管理" tabindex="-1">第9章 用户及组管理 <a class="header-anchor" href="#第9章-用户及组管理" aria-label="Permalink to &quot;第9章 用户及组管理&quot;">​</a></h1><h2 id="_9-1-useradd-添加新用户" tabindex="-1">9.1 useradd 添加新用户 <a class="header-anchor" href="#_9-1-useradd-添加新用户" aria-label="Permalink to &quot;9.1 useradd 添加新用户&quot;">​</a></h2><p>(注意:当前用户必须有添加用户的权限)</p><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">useradd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：添加新用户）</span></span></code></pre></div><p>2）案例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# useradd hadoop</span></span></code></pre></div><h2 id="_9-2-passwd-设置用户密码" tabindex="-1">9.2 passwd 设置用户密码 <a class="header-anchor" href="#_9-2-passwd-设置用户密码" aria-label="Permalink to &quot;9.2 passwd 设置用户密码&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">passwd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：设置用户密码）</span></span></code></pre></div><p>​ 2）案例</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 ~]# passwd hadoop</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592708043758.png" alt="1592708043758"></p><h2 id="_9-3-id-判断用户是否存在" tabindex="-1">9.3 id 判断用户是否存在 <a class="header-anchor" href="#_9-3-id-判断用户是否存在" aria-label="Permalink to &quot;9.3  id 判断用户是否存在&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">id</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span></span></code></pre></div><p>2）案例：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 ~]#id hadoop</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592708101097.png" alt="1592708101097"></p><h2 id="_9-4-su-切换用户" tabindex="-1">9.4 su 切换用户 <a class="header-anchor" href="#_9-4-su-切换用户" aria-label="Permalink to &quot;9.4 su 切换用户&quot;">​</a></h2><p>1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>su 用户名称 （功能描述：切换用户，只能获得用户的执行行权限，不能获得环境变量）</span></span>
<span class="line"><span></span></span>
<span class="line"><span>su - 用户名称 （功能描述：切换到用户并获得该用户的环境变量及执行权限）</span></span></code></pre></div><p>2）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#su hadoop</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#su - hadoop</span></span></code></pre></div><h2 id="_9-5-userdel-删除用户" tabindex="-1">9.5 userdel 删除用户 <a class="header-anchor" href="#_9-5-userdel-删除用户" aria-label="Permalink to &quot;9.5 userdel 删除用户&quot;">​</a></h2><p>1）基本语法：注意区别</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）userdel</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：删除用户但保存用户主目录）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）userdel</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -r</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：用户和用户主目录，都删除）</span></span></code></pre></div><p>2）案例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（1）删除用户但保存用户主目录</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#userdel hadoop</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">（2）删除用户和用户主目录，都删除</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#userdel -r hadoop</span></span></code></pre></div><h2 id="_9-6-who-查看登录用户信息" tabindex="-1">9.6 who 查看登录用户信息 <a class="header-anchor" href="#_9-6-who-查看登录用户信息" aria-label="Permalink to &quot;9.6 who 查看登录用户信息&quot;">​</a></h2><p>1）基本语法</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>（1）whoami （功能描述：显示自身用户名称）</span></span>
<span class="line"><span></span></span>
<span class="line"><span>（2）who am i （功能描述：显示登录用户的用户名）</span></span>
<span class="line"><span></span></span>
<span class="line"><span>（3）who （功能描述：看当前有哪些用户登录到了了本台机器器上）</span></span></code></pre></div><p>2）案例</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 ~]# whoami</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[root@linux121 ~]# who am i</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[root@linux121 ~]# who</span></span></code></pre></div><h2 id="_9-7-设置linux普通用户具有root权限即sudo的使用" tabindex="-1">9.7 设置Linux普通用户具有root权限即sudo的使用 <a class="header-anchor" href="#_9-7-设置linux普通用户具有root权限即sudo的使用" aria-label="Permalink to &quot;9.7  设置Linux普通用户具有root权限即sudo的使用&quot;">​</a></h2><p>1)sudo命令</p><p>sudo是linux系统管理指令，是允许<a href="https://baike.baidu.com/item/%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%91%98/1503845" target="_blank" rel="noreferrer">系统管理员</a>让普通用户执行一些或者全部的root命令的一个工具，如halt，reboot，su等等。这样不仅减少了root用户的登录 和管理时间，同样也提高了安全性 。</p><p>2）修改配置文件 修改 /etc/sudoers 文件，找到下面一行，在root下面添加一行，如下所示：</p><p>vim /etc/sudoers</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>## Allow root to run any commands anywhere</span></span>
<span class="line"><span>root ALL=(ALL) ALL</span></span>
<span class="line"><span>tom ALL=(ALL) ALL</span></span></code></pre></div><p>3)使用tom用户登录,操作管理员命令</p><p>本质:使用临时管理员权限</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>#不切换root用户,也可以完成添加用户的功能</span></span>
<span class="line"><span>sudo useradd  lisi</span></span>
<span class="line"><span>sudo passwd  lisi</span></span></code></pre></div><h2 id="_9-8-cat-etc-passwd-查看创建了哪些用户" tabindex="-1">9.8 cat /etc/passwd 查看创建了哪些用户 <a class="header-anchor" href="#_9-8-cat-etc-passwd-查看创建了哪些用户" aria-label="Permalink to &quot;9.8 cat /etc/passwd 查看创建了哪些用户&quot;">​</a></h2><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cat /etc/passwd</span></span></code></pre></div><h2 id="_9-9-用户组管理命令" tabindex="-1">9.9 用户组管理命令 <a class="header-anchor" href="#_9-9-用户组管理命令" aria-label="Permalink to &quot;9.9 用户组管理命令&quot;">​</a></h2><p>每个用户都有一个用户组，系统可以对一个用户组中的所有用户进行集中管理。不同Linux 系统对用户 组的规定有所不同，如Linux下的用户属于与它同名的用户组，这个用户组在创建用户时同时创建。 用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对/etc/group文件的更新</p><h3 id="_9-9-1-groupadd-新增组" tabindex="-1">9.9.1 groupadd 新增组 <a class="header-anchor" href="#_9-9-1-groupadd-新增组" aria-label="Permalink to &quot;9.9.1 groupadd 新增组&quot;">​</a></h3><p>1）基本语法</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">groupadd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 组名</span></span></code></pre></div><p>2）案例： 添加一个hadoop组</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#groupadd hadoop</span></span></code></pre></div><h3 id="_9-9-2-groupdel删除组" tabindex="-1">9.9.2 groupdel删除组 <a class="header-anchor" href="#_9-9-2-groupdel删除组" aria-label="Permalink to &quot;9.9.2 groupdel删除组&quot;">​</a></h3><p>1）基本语法：</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">groupdel 组名</span></span></code></pre></div><p>2）案例例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# groupdel hadoop</span></span></code></pre></div><h3 id="_9-9-3-groupmod修改组" tabindex="-1">9.9.3 groupmod修改组 <a class="header-anchor" href="#_9-9-3-groupmod修改组" aria-label="Permalink to &quot;9.9.3 groupmod修改组&quot;">​</a></h3><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">groupmod</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 新组名</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 老组名</span></span></code></pre></div><p>2）案例 修改hadoop组名称为hadoop1</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 hadoop]# groupmod -n hadoop1 hadoop</span></span></code></pre></div><h3 id="_9-9-4-cat-etc-group-查看创建了哪些组" tabindex="-1">9.9.4 cat /etc/group 查看创建了哪些组 <a class="header-anchor" href="#_9-9-4-cat-etc-group-查看创建了哪些组" aria-label="Permalink to &quot;9.9.4 cat /etc/group 查看创建了哪些组&quot;">​</a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/group</span></span></code></pre></div><h2 id="_9-10-usermod修改用户" tabindex="-1">9.10 usermod修改用户 <a class="header-anchor" href="#_9-10-usermod修改用户" aria-label="Permalink to &quot;9.10 usermod修改用户&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">usermod</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -g</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户组</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用户名</span></span></code></pre></div><p>2）案例： 将用户hadoop加入mygroup用户组</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]#usermod -g mygroup hadoop</span></span></code></pre></div><h1 id="第10章-文件权限" tabindex="-1">第10章 文件权限 <a class="header-anchor" href="#第10章-文件权限" aria-label="Permalink to &quot;第10章 文件权限&quot;">​</a></h1><p>Linux系统是一种典型的多用户系统，不同的用户处于不同的地位，拥有不同的权限。为了保护系统的安全性，Linux系统对不同的用户访问同一文件（包括目录文件）的权限做了不同的规定。在Linux中我们可以使用ll或者ls –l命令来显示一个文件的属性以及文件所属的用户和组。</p><h2 id="_10-1-文件权限" tabindex="-1">10.1 文件权限 <a class="header-anchor" href="#_10-1-文件权限" aria-label="Permalink to &quot;10.1 文件权限&quot;">​</a></h2><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1558583116607.png" alt="1558583116607"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1534510730127.png" alt="1534510730127"></p><p>权限分段，每一段代表不同的用户：</p><p>属主权限：当前文件所属用户的权限，在Linux中每一个文件都有所属的用户</p><p>属组权限：当前文件的用户所在组的其它成员的权限</p><p>其它用户权限：跟文件所属用户不在同组的其它用户的权限</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">每一段中的内容都是一样的，分别限定：读（r</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">=4）、写（w=2）、执行（x=1）</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">rwx</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		7</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备所有权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">421</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">rw-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备读写权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">420</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">r-x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		5</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备读和执行权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">401</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">r--</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		4</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备只读权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">400</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-wx</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备写和执行权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">021</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-w-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备写权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">020</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">--x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">		具备执行权限</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">001</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">---</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		0</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		000</span></span></code></pre></div><p>问题:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 777 什么意思?</span></span>
<span class="line"><span>2 644 什么意思</span></span>
<span class="line"><span>3 755 什么意思?</span></span></code></pre></div><p>答案</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>777 所属用户具有 读写执行权限, 所属同组用户具有 读写执行权限, 其他人具有 读写执行权限</span></span>
<span class="line"><span>644 所属用户具有 读写权限, 所属同组用户具有 读权限, 其他人具有 读权限</span></span>
<span class="line"><span>755 所属用户具有 读写执行权限, 所属同组用户具有 读执行权限, 其他人具有 读执行权限</span></span></code></pre></div><h2 id="_10-2-文件权限管理" tabindex="-1">10.2 文件权限管理 <a class="header-anchor" href="#_10-2-文件权限管理" aria-label="Permalink to &quot;10.2 文件权限管理&quot;">​</a></h2><p>修改文件权限</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1534510788701.png" alt="1534510788701"></p><p>需求:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>1 新增 /usr/tmp/1.txt 文件 且 查看 权限</span></span>
<span class="line"><span>2 修改权限为 777(方式一)</span></span>
<span class="line"><span>3 修改权限为 755(方式二)</span></span></code></pre></div><p>答案</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# touch /usr/tmp/1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# ll</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-rw-r--r--.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 7月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  24</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# chmod 777 1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# ll</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-rwxrwxrwx.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 7月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  24</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# chmod u</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">rwx,</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">g</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">rx,</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">o</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">rx</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> 1.txt</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@itheima16 tmp]# ll</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">总用量</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-rwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 7月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  24</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 05:15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1.txt</span></span></code></pre></div><h2 id="_10-3-chown改变所有者" tabindex="-1">10.3 chown改变所有者 <a class="header-anchor" href="#_10-3-chown改变所有者" aria-label="Permalink to &quot;10.3 chown改变所有者&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">chown</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 最终用户</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：改变文件或者目录的所有者）</span></span></code></pre></div><p>2）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# chown hadoop test1.txt</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# ls -al</span></span></code></pre></div><h2 id="_10-4-chgrp改变所属组" tabindex="-1">10.4 chgrp改变所属组 <a class="header-anchor" href="#_10-4-chgrp改变所属组" aria-label="Permalink to &quot;10.4 chgrp改变所属组&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">chgrp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 最终用户组</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> （功能描述：改变文件或者目录的所属组）</span></span></code></pre></div><p>2）案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# chgrp hadoop test1.test</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 test]# ls -al</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">-rwxr-xr-x.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> hadoop</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 551</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 4月</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 23</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 13:02</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> test1.java</span></span></code></pre></div><h1 id="第11章-系统管理与进程管理" tabindex="-1">第11章 系统管理与进程管理 <a class="header-anchor" href="#第11章-系统管理与进程管理" aria-label="Permalink to &quot;第11章  系统管理与进程管理&quot;">​</a></h1><h2 id="_11-1-磁盘信息" tabindex="-1">11.1 磁盘信息 <a class="header-anchor" href="#_11-1-磁盘信息" aria-label="Permalink to &quot;11.1 磁盘信息&quot;">​</a></h2><table tabindex="0"><thead><tr><th>序号</th><th>命令</th><th>作用</th></tr></thead><tbody><tr><td>1</td><td>df -h</td><td>disk free 显示磁盘剩余空间</td></tr><tr><td>2</td><td>du -h [目录名称]</td><td>disk usage 显示目录下的目录大小</td></tr></tbody></table><ul><li>选项说明</li></ul><table tabindex="0"><thead><tr><th>参数</th><th>含义</th></tr></thead><tbody><tr><td>-h</td><td>以人性化的方式显示文件大小</td></tr></tbody></table><h2 id="_11-2-ps查看系统中所有进程" tabindex="-1">11.2 ps查看系统中所有进程 <a class="header-anchor" href="#_11-2-ps查看系统中所有进程" aria-label="Permalink to &quot;11.2 ps查看系统中所有进程&quot;">​</a></h2><p>进程是正在执行的一个程序或命令，每一个进程都是一个运行的实体，都有自己的地址空间，并占用一定的系统资源。</p><p>1）基本语法：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>ps -aux （功能描述：查看系统中所有进程）</span></span></code></pre></div><table tabindex="0"><thead><tr><th>选项</th><th>含义</th></tr></thead><tbody><tr><td>a</td><td>显示终端上的所有进程, 包括其他用户的进程</td></tr><tr><td>u</td><td>显示进程的详细状态</td></tr><tr><td>x</td><td>显示没有控制终端的进程</td></tr></tbody></table><blockquote><p>注意:</p><p>ps aux 和ps -ef  两者的输出结果差别不大，但展示风格不同。aux是BSD风格，-ef是System V风格</p></blockquote><p>2）功能说明</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>USER：该进程是由哪个用户产生的</span></span>
<span class="line"><span></span></span>
<span class="line"><span>PID：进程的ID号</span></span>
<span class="line"><span></span></span>
<span class="line"><span>%CPU：该进程占用CPU资源的百分比，占用越高，进程越耗费资源；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>%MEM：该进程占用物理理内存的百分比，占用越高，进程越耗费资源；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>VSZ：该进程占用虚拟内存的大小，单位KB；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>RSS：该进程占用实际物理理内存的大小，单位KB；</span></span>
<span class="line"><span></span></span>
<span class="line"><span>TTY：该进程是在哪个终端中运行行的。其中tty1-tty7代表本地控制台终端，tty1-tty6是本地的字符界面</span></span>
<span class="line"><span></span></span>
<span class="line"><span>终端，tty7是图形终端。pts/0-255代表虚拟终端。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>STAT：进程状态。常见的状态有：R：运行、S：睡眠、T：停止状态、s：包含子进程、+：位于后台</span></span>
<span class="line"><span></span></span>
<span class="line"><span>START：该进程的启动时间</span></span>
<span class="line"><span></span></span>
<span class="line"><span>TIME：该进程占用CPU的运算时间，注意不是系统时间</span></span>
<span class="line"><span></span></span>
<span class="line"><span>COMMAND：产生此进程的命令名</span></span></code></pre></div><h2 id="_11-3-top查看系统健康状态" tabindex="-1">11.3 top查看系统健康状态 <a class="header-anchor" href="#_11-3-top查看系统健康状态" aria-label="Permalink to &quot;11.3 top查看系统健康状态&quot;">​</a></h2><p>1）基本命令</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>top [选项]</span></span></code></pre></div><p>（1）选项：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>-d 秒数：指定top命令每隔几秒更新。默认是3秒。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>-i：使top不显示任何闲置或者僵死进程。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>-p：通过指定监控进程ID来仅仅监控某个进程的状态。</span></span></code></pre></div><p>（2）操作选项，即在执行top命令之后，与top命令进行交互：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>P： 以CPU使用率排序，默认就是此项</span></span>
<span class="line"><span>M：以内存的使用率排序</span></span>
<span class="line"><span>N： 以PID排序</span></span>
<span class="line"><span>q： 退出top</span></span></code></pre></div><p>（3）查询结果字段解释</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597918705895.png" alt="1597918705895"></p><p>第一行信息为任务队列列信息</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723059983.png" alt="1592723059983"></p><p>第二行为进程信息</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723080526.png" alt="1592723080526"></p><p>第三行为CPU信息</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723100162.png" alt="1592723100162"></p><p>第四行为物理内存信息</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723125616.png" alt="1592723125616"></p><p>第五行为交换分区（swap）信息</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723146910.png" alt="1592723146910"></p><p>2）案例</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 hadoop]# top -d 1</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[root@linux121 hadoop]# top -i</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[root@linux121 hadoop]# top -p 2575</span></span></code></pre></div><p>执行上述命令后，可以按P、M、N对查询出的进程结果进行排序</p><h2 id="_11-4-kill终止进程" tabindex="-1">11.4 kill终止进程 <a class="header-anchor" href="#_11-4-kill终止进程" aria-label="Permalink to &quot;11.4 kill终止进程&quot;">​</a></h2><p>1）基本语法：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">kill</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -9</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pid进程号</span></span></code></pre></div><p>选项 -9 表示强迫进程立即停止</p><p>举例:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@linux121 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# kill -9 5102</span></span></code></pre></div><h2 id="_11-5-netstat显示网络统计信息" tabindex="-1">11.5 netstat显示网络统计信息 <a class="header-anchor" href="#_11-5-netstat显示网络统计信息" aria-label="Permalink to &quot;11.5 netstat显示网络统计信息&quot;">​</a></h2><p><strong>1） netstat作用</strong></p><p>netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据，一般用于检验本机各端口的网络连接情况</p><p><strong>2）安装命令</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">yum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> net-tools</span></span></code></pre></div><p><strong>3）基本语法</strong></p><p>选项：</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1597925218725.png" alt="1597925218725"></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">NETSTAT</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  -a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            显示所有连接和监听端口。</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            显示以太网统计信息。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  				广播的数量</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  -n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            以数字形式显示地址和端口号。</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            显示与每个连接相关的所属进程</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ID</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 。</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">  -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> proto</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">      显示</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> proto</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 指定的协议的连接；proto</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 可以是下列协议之一:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> TCP</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 、UDP</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 、TCPv6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 或</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> UDPv6</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 。</span></span></code></pre></div><p>常用选项</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netstat</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 本选项用于显示关于以太网的统计数据。</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netstat</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -r</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 本选项可以显示关于路由表的信息，类似于后面所讲使用route</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> print</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 命令时看到的</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 信息。除了显示有效路由外，还显示当前有效的连接。</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netstat</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 本选项显示一个所有的有效连接信息列表，包括已建立的连接（ESTABLISHED</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ），也包括监听连接请求（LISTENING</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ）的那些连接，断开连接（CLOSE_WAIT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ）或者处于联机等待状态的（TIME_WAIT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ）等</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netstat</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 显示所有已建立的有效连接。</span></span></code></pre></div><p>组合用法:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">netstat</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -anp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 查看这个系统目前网络状况.</span></span></code></pre></div><p>查看端口22的使用情况</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@linux121 hadoop-2.7.2]# netstat -anp | grep 22</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723411114.png" alt="1592723411114"></p><h1 id="第12章-软件安装" tabindex="-1">第12章 软件安装 <a class="header-anchor" href="#第12章-软件安装" aria-label="Permalink to &quot;第12章  软件安装&quot;">​</a></h1><h2 id="_12-1-rpm-软件包管理器" tabindex="-1">12.1 rpm 软件包管理器 <a class="header-anchor" href="#_12-1-rpm-软件包管理器" aria-label="Permalink to &quot;12.1 rpm 软件包管理器&quot;">​</a></h2><h3 id="_12-1-1-目标" tabindex="-1">12.1.1 目标 <a class="header-anchor" href="#_12-1-1-目标" aria-label="Permalink to &quot;12.1.1 目标&quot;">​</a></h3><ul><li>通过 <code>rpm命令</code> 实现对软件 的安装、查询、卸载</li><li>RPM  是Red-Hat Package Manager（RPM软件包管理器）的缩写</li><li>虽然 打上了 red-hat 的标记, 但是理念开放, 很多发行版都采用, 已经成为行业标准</li></ul><h3 id="_12-1-2-路径" tabindex="-1">12.1.2 路径 <a class="header-anchor" href="#_12-1-2-路径" aria-label="Permalink to &quot;12.1.2 路径&quot;">​</a></h3><ul><li>第一步: rpm包 的查询命令</li><li>第二步: rpm包 的 卸载</li><li>第三步: rpm包 的 安装</li></ul><h3 id="_12-1-3-实现" tabindex="-1">12.1.3 实现 <a class="header-anchor" href="#_12-1-3-实现" aria-label="Permalink to &quot;12.1.3 实现&quot;">​</a></h3><p>第一步: rpm包 的 查询命令</p><table tabindex="0"><thead><tr><th>选项</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td><code>-q</code></td><td>query</td><td>查询</td></tr><tr><td><code>-a</code></td><td>all</td><td>所有</td></tr><tr><td><code>-i</code></td><td>info</td><td>信息</td></tr><tr><td><code>-l</code></td><td>list</td><td>显示所有相关文件</td></tr><tr><td><code>-f</code></td><td>file</td><td>文件, 显示文件对应 <code>rpm</code>包</td></tr></tbody></table><ul><li><p>查询已安装的<strong>rpm</strong>列表</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">qa </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> grep XXX</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">qa </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> less</span></span></code></pre></div></li><li><p>查询软件包信息</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">qi 软件全包名</span></span></code></pre></div></li><li><p>查看一个rpm包中的文件安装到那里去了？</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ql 软件全包名</span></span></code></pre></div></li><li><p>查看指定文件归属于那个软件包</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">qf 文件的全路径</span></span></code></pre></div></li></ul><p>第二步: rpm包 的 卸载</p><table tabindex="0"><thead><tr><th>命令</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td><code>rpm -e 软件包名称</code></td><td>erase 清除</td><td>卸载rpm软件包</td></tr><tr><td><code>rpm -e --nodeps 软件包名称</code></td><td>Don’t check dependencies</td><td>卸载前 跳过 依赖检查</td></tr></tbody></table><p>第三步: rpm包 的 安装</p><table tabindex="0"><thead><tr><th>命令</th><th>含义</th></tr></thead><tbody><tr><td><code>rpm -ivh rpm包的全路径</code></td><td>安装 rpm 包</td></tr></tbody></table><table tabindex="0"><thead><tr><th>参数</th><th>英文</th><th>含义</th></tr></thead><tbody><tr><td><code>-i</code></td><td>install</td><td>安装</td></tr><tr><td><code>-v</code></td><td>verbose</td><td>打印提示信息</td></tr><tr><td><code>-h</code></td><td>hase</td><td>显示安装进度</td></tr></tbody></table><p>小结</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 1 查询</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">qa </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> grep rpm包</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 2 卸载</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e rpm全包名</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">nodeps rpm全包名</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 3 安装</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ivh rpm包的全路径</span></span></code></pre></div><h2 id="_12-2-yum" tabindex="-1">12.2 yum <a class="header-anchor" href="#_12-2-yum" aria-label="Permalink to &quot;12.2 yum&quot;">​</a></h2><h3 id="_12-2-1-yum介绍" tabindex="-1">12.2.1 yum介绍 <a class="header-anchor" href="#_12-2-1-yum介绍" aria-label="Permalink to &quot;12.2.1 yum介绍&quot;">​</a></h3><ul><li><code>Yum</code>（全称为 <code>Yellow dog Updater, Modified</code>）<strong>本质上</strong> 也是一个 <strong>软件包管理器</strong>。</li><li><strong>特点:</strong> 基于 <code>RPM</code> 包管理，能够从指定的服务器 <strong>自动下载、 自动安装、 自动处理依赖性关系</strong></li></ul><h3 id="_12-2-2-yum原理" tabindex="-1">12.2.2 yum原理 <a class="header-anchor" href="#_12-2-2-yum原理" aria-label="Permalink to &quot;12.2.2 yum原理&quot;">​</a></h3><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598008879449.png" alt="1592728181455"></p><h3 id="_12-2-3-常用命令" tabindex="-1">12.2.3 常用命令 <a class="header-anchor" href="#_12-2-3-常用命令" aria-label="Permalink to &quot;12.2.3 常用命令&quot;">​</a></h3><p>注意: <strong>必须联网</strong></p><table tabindex="0"><thead><tr><th>命令</th><th>含义</th></tr></thead><tbody><tr><td>`yum list</td><td>grep 需要的软件名`</td></tr><tr><td><code>yum -y install 需要的软件包</code></td><td>下载安装</td></tr><tr><td><code>yum -y remove 需要卸载的软件包</code></td><td>卸载</td></tr><tr><td><code>yum repolist</code></td><td>列出设定yum源信息</td></tr><tr><td><code>yum clean all</code></td><td>清除yum缓存信息</td></tr></tbody></table><h2 id="_12-3-安装httpd软件" tabindex="-1">12.3 安装httpd软件 <a class="header-anchor" href="#_12-3-安装httpd软件" aria-label="Permalink to &quot;12.3 安装httpd软件&quot;">​</a></h2><ul><li><h4 id="安装httpd" tabindex="-1">安装httpd: <a class="header-anchor" href="#安装httpd" aria-label="Permalink to &quot;安装httpd:&quot;">​</a></h4><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">yum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">y install httpd</span></span></code></pre></div></li><li><h4 id="启动-httpd-服务" tabindex="-1">启动 httpd 服务 <a class="header-anchor" href="#启动-httpd-服务" aria-label="Permalink to &quot;启动 httpd 服务&quot;">​</a></h4><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">service httpd start</span></span></code></pre></div></li><li><h4 id="测试" tabindex="-1">测试 <a class="header-anchor" href="#测试" aria-label="Permalink to &quot;测试&quot;">​</a></h4><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">http:</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">//</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">192.168</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">80.100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">80</span></span></code></pre></div></li><li><h4 id="问题-发现无法访问" tabindex="-1">问题: 发现无法访问? <a class="header-anchor" href="#问题-发现无法访问" aria-label="Permalink to &quot;问题: 发现无法访问?&quot;">​</a></h4><ul><li><h4 id="原因-因为-linux-的防火墙-禁止他人-访问自己的80端口" tabindex="-1">原因: 因为 linux 的防火墙 禁止他人 访问自己的80端口 <a class="header-anchor" href="#原因-因为-linux-的防火墙-禁止他人-访问自己的80端口" aria-label="Permalink to &quot;原因: 因为 linux 的防火墙 禁止他人 访问自己的80端口&quot;">​</a></h4></li><li><h4 id="解决-通知-防火墙放行" tabindex="-1">解决: 通知 防火墙放行 <a class="header-anchor" href="#解决-通知-防火墙放行" aria-label="Permalink to &quot;解决: 通知 防火墙放行&quot;">​</a></h4></li></ul><p><strong>关闭防火墙</strong></p></li></ul><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>systemctl stop firewalld     查看防火墙状态</span></span></code></pre></div><h2 id="_12-4-安装jdk" tabindex="-1">12.4 安装JDK <a class="header-anchor" href="#_12-4-安装jdk" aria-label="Permalink to &quot;12.4 安装JDK&quot;">​</a></h2><p>系统默认安装OpenJDK，首先需要删除OpenJDK</p><p>1、查看以前是不是安装了openjdk</p><p>如果不是root用户需要切换到root用户（su - root）</p><p>命令：<code>rpm -qa | grep java</code></p><p>显示如下：（有则卸载，没有就不用），注意版本可能会有些不一样，以实际操作的为准。</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">tzdata</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">java</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">2013g</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">el6.noarch</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">java</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">openjdk</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.7</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.45</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2.4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">3.3</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.el6.x86_64</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">java</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">openjdk</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.6</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.66</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.13</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">el6.x86_64</span></span></code></pre></div><p>2、卸载openjdk：</p><p>（其中参数“tzdata-java-2013j-1.el6.noarch”为上面查看中显示的结果，粘进来就行，如果你显示的不一样，请复制你查询到的结果）</p><p>rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686 rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.i686 rpm -e --nodeps tzdata-java-2013g-1.el6.noarch</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e 			erase package(uninstall)			移除包(卸载)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">nodeps	</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> not verify package dependencies	不要验证包依赖关系</span></span></code></pre></div><p>3、安装jdk</p><p>（1）、切换到root用户并进入usr目录： cd /usr</p><p>（2）、在usr目录下创建java文件夹： mkdir java</p><p>（3）、将jdk1.8.0_141.tar.gz拷贝或上传到java目录下（也可以用工具）</p><p>（4）、进入/usr/java文件夹下：cd /usr/java/</p><p>（5）、修改权限，参数“jdk1.8.0_141.tar.gz”为你自己上传的jdk安装文件</p><p>chmod 755 jdk1.8.0_141.tar.gz</p><p>（6）、解压：tar –zxvf jdk1.8.0_141.tar.gz</p><p>（7）、配置环境变量</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">vi</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/profile</span></span></code></pre></div><p>添加内容：</p><p>export 主要用来设置环境变量</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> JAVA_HOME</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/usr/java/jdk1.8.0_141/</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> CLASSPATH</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PATH</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$PATH:${JAVA_HOME}/bin</span></span></code></pre></div><p>（8）、重新编译环境变量</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">source</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/profile</span></span></code></pre></div><p>（9）、测试</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">java</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -version</span></span></code></pre></div><h2 id="_12-5-安装tomcat" tabindex="-1">12.5 安装tomcat <a class="header-anchor" href="#_12-5-安装tomcat" aria-label="Permalink to &quot;12.5 安装tomcat&quot;">​</a></h2><p>安装Tomcat</p><p>1、创建安装目录：mkdir /usr/tomcat</p><p>2、给apache-tomcat-7.0.57.tar.gz 文件权限</p><p>3、解压tomcat压缩文件：<code>tar -zxvf apache-tomcat-7.0.57.tar.gz -C /user/tomcat</code></p><p>注意，这里也可以只打开tomcat所需端口：8080</p><p>4、启动tomcat：</p><p>进入tomcat的bin目录：<code>cd /usr/tomcat/apache-tomcat-7.0.57/bin/</code></p><p>启动tomcat web服务器：<code>./startup.sh</code></p><p>访问：<code>192.168.80.100:8080</code></p><p>5、停止tomcat</p><p>：<code>./shutdown.sh</code></p><p>6、查看tomcat日志信息：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -200f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/tomcat/apache-tomcat-7.0.57/logs/catalina.out</span></span></code></pre></div><p>200表示最后显示行数</p><p>也可以用组合命令，启动并查看日志：</p><p>进入tomcat的bin目录</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./startup.sh</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tail</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -200f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ../logs/catalina.out</span></span></code></pre></div><h2 id="_12-6-安装mysql" tabindex="-1">12.6 安装mysql <a class="header-anchor" href="#_12-6-安装mysql" aria-label="Permalink to &quot;12.6 安装mysql&quot;">​</a></h2><ul><li>下面看看如何在CentOS7系统上安装 MySQL5.6.44</li></ul><h3 id="_12-6-1-查询系统自带的mysql" tabindex="-1">12.6.1 查询系统自带的mysql <a class="header-anchor" href="#_12-6-1-查询系统自带的mysql" aria-label="Permalink to &quot;12.6.1 查询系统自带的mysql&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>[root@hadoop01 yum.repos.d]# rpm -qa | grep mysql</span></span>
<span class="line"><span>mysql-libs-5.1.73-8.el6_8.x86_64</span></span></code></pre></div><h3 id="_12-6-2-卸载系统自带的mysql" tabindex="-1">12.6.2 卸载系统自带的mysql <a class="header-anchor" href="#_12-6-2-卸载系统自带的mysql" aria-label="Permalink to &quot;12.6.2 卸载系统自带的mysql&quot;">​</a></h3><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rpm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">e </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">--</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">nodeps mysql</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">libs</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">73</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">8.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">el6_8.x86_64</span></span></code></pre></div><h3 id="_12-6-3-下载安装官网yum源" tabindex="-1">12.6.3 下载安装官网yum源 <a class="header-anchor" href="#_12-6-3-下载安装官网yum源" aria-label="Permalink to &quot;12.6.3 下载安装官网yum源&quot;">​</a></h3><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">查看yum源仓库</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ll </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">etc</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">yum.repos.d</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">下载yum源</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">wget </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">P </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">usr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">software http:</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">//</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">repo.mysql.com</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">mysql</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">community</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">release</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">el6</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">5.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">noarch.rpm</span></span></code></pre></div><ul><li>注意: <strong>需要联网</strong></li></ul><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731253408.png" alt="1592731253408"></p><h3 id="_12-6-4-安装下载好的rpm文件" tabindex="-1">12.6.4 安装下载好的rpm文件 <a class="header-anchor" href="#_12-6-4-安装下载好的rpm文件" aria-label="Permalink to &quot;12.6.4 安装下载好的rpm文件&quot;">​</a></h3><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cd /usr/software</span></span>
<span class="line"><span>rpm -ivh mysql-community-release-el6-5.noarch.rpm</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731293229.png" alt="1592731293229"></p><h3 id="_12-6-5-安装mysql-服务器" tabindex="-1">12.6.5 安装mysql 服务器 <a class="header-anchor" href="#_12-6-5-安装mysql-服务器" aria-label="Permalink to &quot;12.6.5 安装mysql 服务器&quot;">​</a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">yum</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mysql-community-server</span></span></code></pre></div><ul><li>注意: 需要<strong>联网下载</strong>, 估计需要等待十几分钟!</li><li>测试是否安装成功</li></ul><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731317343.png" alt="1592731317343"></p><h3 id="_12-6-6-启动服务" tabindex="-1">12.6.6 启动服务 <a class="header-anchor" href="#_12-6-6-启动服务" aria-label="Permalink to &quot;12.6.6 启动服务&quot;">​</a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">service</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mysqld</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> start</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">如果出现:serivce:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> not</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> found</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">安装service</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">yum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> initscripts</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731337922.png" alt="1592731337922"></p><h3 id="_12-6-7-修改密码" tabindex="-1">12.6.7 修改密码 <a class="header-anchor" href="#_12-6-7-修改密码" aria-label="Permalink to &quot;12.6.7 修改密码&quot;">​</a></h3><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731373778.png" alt="1592731373778"></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 设置密码</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/usr/bin/mysqladmin</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -u</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> root</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> password</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;123&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 进入mysql</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mysql</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -uroot</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p123</span></span></code></pre></div><h3 id="_12-6-8-问题1-解决中文乱码" tabindex="-1">12.6.8 问题1: 解决中文乱码 <a class="header-anchor" href="#_12-6-8-问题1-解决中文乱码" aria-label="Permalink to &quot;12.6.8 问题1: 解决中文乱码&quot;">​</a></h3><p>由于MySQL编码原因会导致数据库出现乱码。</p><p><strong>解决办法：</strong></p><p>修改MySQL数据库字符编码为UTF-8，UTF-8包含全世界所有国家需要用到的字符,是国际编码。</p><p><strong>具体操作：</strong></p><h4 id="_12-6-8-1-进入mysql控制台" tabindex="-1">12.6.8.1 进入MySQL控制台 <a class="header-anchor" href="#_12-6-8-1-进入mysql控制台" aria-label="Permalink to &quot;12.6.8.1 进入MySQL控制台&quot;">​</a></h4><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 进入mysql</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mysql</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -uroot</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p123</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 查看编码集 发现不是utf8</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">show</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> variables</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> like</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;character_set_%&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731402495.png" alt="1592731402495"></p><h4 id="_12-6-8-2-修改mysql配置文件" tabindex="-1">12.6.8.2 修改mysql配置文件 <a class="header-anchor" href="#_12-6-8-2-修改mysql配置文件" aria-label="Permalink to &quot;12.6.8.2 修改mysql配置文件&quot;">​</a></h4><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 清空 mysql 配置文件内容</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@Hadoop-NN-01 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/etc/my.cnf</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 修改mysql 软件的编码集</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@Hadoop-NN-01 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# vi /etc/my.cnf</span></span></code></pre></div><p>修改内容如下:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[client]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">default-character-set</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">utf8</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[mysql]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">default-character-set</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">utf8</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[mysqld]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">character-set-server</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">utf8</span></span></code></pre></div><h4 id="_12-6-8-3-重启mysql服务" tabindex="-1">12.6.8.3 重启MySQL服务 <a class="header-anchor" href="#_12-6-8-3-重启mysql服务" aria-label="Permalink to &quot;12.6.8.3 重启MySQL服务&quot;">​</a></h4><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@Hadoop-NN-01 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">~</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]# service mysqld restart</span></span></code></pre></div><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> #查看MySQL字符集</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">show</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> variables</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> like</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;character_set_%&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731426244.png" alt="1592731426244"></p><p>MySQL数据库字符集编码修改完成！</p><h3 id="_12-6-9-问题2-默认情况下-mysql服务端不允许客户端远程访问" tabindex="-1">12.6.9 问题2: 默认情况下 mysql服务端不允许客户端远程访问 <a class="header-anchor" href="#_12-6-9-问题2-默认情况下-mysql服务端不允许客户端远程访问" aria-label="Permalink to &quot;12.6.9 问题2: 默认情况下 mysql服务端不允许客户端远程访问&quot;">​</a></h3><p>问题: 使用客户端 远程 连接mysql报错?</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592731453087.png" alt="1592731453087"></p><ul><li><p>原因: 因为 用户 没有 远程访问的权限</p></li><li><p>解决: 授权</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 给root授权:既可以本地访问, 也可以远程访问</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">grant</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> all</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> privileges</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> on</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> to</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;root&#39;@&#39;%&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> identified</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> by</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;123&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> with</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> grant</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> option</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 刷新权限(可选)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">flush</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> privileges</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre></div></li></ul><h1 id="第13章-大数据linux操作" tabindex="-1">第13章 大数据linux操作 <a class="header-anchor" href="#第13章-大数据linux操作" aria-label="Permalink to &quot;第13章  大数据linux操作&quot;">​</a></h1><h2 id="_13-1-克隆2台机器" tabindex="-1">13.1 克隆2台机器 <a class="header-anchor" href="#_13-1-克隆2台机器" aria-label="Permalink to &quot;13.1 克隆2台机器&quot;">​</a></h2><h3 id="_13-1-1-克隆操作" tabindex="-1">13.1.1 克隆操作 <a class="header-anchor" href="#_13-1-1-克隆操作" aria-label="Permalink to &quot;13.1.1 克隆操作&quot;">​</a></h3><p>关闭当前centos7-1</p><p>右键点击克隆</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177282109.png" alt="1598177238227"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177309123.png" alt="1598177296886"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177327255.png" alt="1598177327255"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177408230.png" alt="1598177408230"></p><p>​ <img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177432930.png" alt="1598177432930"></p><h3 id="_13-1-2-配置克隆后机器" tabindex="-1">13.1.2 配置克隆后机器 <a class="header-anchor" href="#_13-1-2-配置克隆后机器" aria-label="Permalink to &quot;13.1.2 配置克隆后机器&quot;">​</a></h3><ul><li>网络配置文件ifcfg-ens33的ip地址</li></ul><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>vi /etc/sysconfig/network-scripts/ifcfg-ens33</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598177911747.png" alt="1598177911747"></p><p>重启网卡服务器</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> restart</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> network</span></span></code></pre></div><p>检查ip地址是否更变</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ip</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> addr</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598178081162.png" alt="1598178081162"></p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598178134115.png" alt="1598178134115"></p><ul><li>hostname主机名，不要跟源克隆机一致</li></ul><p>查看主机名命令</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">hostnamectl</span></span></code></pre></div><p>更改主机名</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">hostnamectl </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">set-hostname</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> xxx</span></span></code></pre></div><p>重启机器<code>reboot</code></p><h2 id="_13-2-关闭三台虚拟机防火墙" tabindex="-1">13.2 关闭三台虚拟机防火墙 <a class="header-anchor" href="#_13-2-关闭三台虚拟机防火墙" aria-label="Permalink to &quot;13.2 关闭三台虚拟机防火墙&quot;">​</a></h2><p>1.查看防火墙状态</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> status</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> firewalld</span></span></code></pre></div><p>2.设置防火墙停用状态</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> stop</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> firewalld</span></span></code></pre></div><p>3.设置防火墙功能失效,开机自动关闭</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">systemctl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> disable</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> firewalld</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723609687.png" alt="1592723609687"></p><h2 id="_13-3-三台机器关闭selinux" tabindex="-1">13.3 三台机器关闭selinux <a class="header-anchor" href="#_13-3-三台机器关闭selinux" aria-label="Permalink to &quot;13.3 三台机器关闭selinux&quot;">​</a></h2><p>安全增强型 Linux（Security-Enhanced Linux）简称 SELinux，它是一个 Linux 内核模块，也是 Linux 的一个安全子系统。</p><p>关闭安全策略否则SELinux服务开启后导致SSH连接异常。</p><p>修改文件</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">vi</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/selinux/config</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592723644245.png" alt="1592723644245"></p><h2 id="_13-4-三台机器免密登录" tabindex="-1">13.4 三台机器免密登录 <a class="header-anchor" href="#_13-4-三台机器免密登录" aria-label="Permalink to &quot;13.4 三台机器免密登录&quot;">​</a></h2><h3 id="_13-4-1-ssh协议-安全外壳协议" tabindex="-1">13.4.1 ssh协议[安全外壳协议] <a class="header-anchor" href="#_13-4-1-ssh协议-安全外壳协议" aria-label="Permalink to &quot;13.4.1 ssh协议[安全外壳协议]&quot;">​</a></h3><blockquote><p>​ SSH 为 <a href="https://baike.baidu.com/item/Secure%20Shell" target="_blank" rel="noreferrer">Secure Shell</a> 的缩写，由 IETF 的网络小组（Network Working Group）所制定；SSH 为建立在应用层基础上的安全协议。SSH 是较可靠，专为<a href="https://baike.baidu.com/item/%E8%BF%9C%E7%A8%8B%E7%99%BB%E5%BD%95/1071998" target="_blank" rel="noreferrer">远程登录</a>会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。</p></blockquote><p>SSH提供两种级别的安全验证：</p><p><strong>第一种级别（基于口令的安全验证）</strong></p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>只要你知道自己帐号和口令，就可以登录到远程主机。所有传输的数据都会被加密，但是不能保证你正在连接的服务器就是你想连接的服务器。可能会有别的服务器在冒充真正的服务器，也就是受到“中间人”这种方式的攻击。</span></span></code></pre></div><p><strong>第二种级别（基于密匙的安全验证）</strong></p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>需要依靠密匙，也就是你必须为自己创建一对密匙，并把公用密匙放在需要访问的服务器上。如果你要连接到SSH服务器上，客户端软件就会向服务器发出请求，请求用你的密匙进行安全验证。</span></span></code></pre></div><h3 id="_13-4-2-ssh基于密码远程登录" tabindex="-1">13.4.2 ssh基于密码远程登录 <a class="header-anchor" href="#_13-4-2-ssh基于密码远程登录" aria-label="Permalink to &quot;13.4.2 ssh基于密码远程登录&quot;">​</a></h3><table tabindex="0"><thead><tr><th>命令</th><th>含义</th></tr></thead><tbody><tr><td>ssh ip地址</td><td>登录到远程指定的机器上（需要输入用户名和密码）</td></tr></tbody></table><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598191574815.png" alt="1598191574815"></p><p>可以通过主机名登录</p><p>需要配置主机名和ip地址的映射关系</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">分别的在centos7-1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  centos7-2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  centos7-3中配置</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">vi</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/hosts</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598199455415.png" alt="1598199455415"></p><p>接下来就可以是用主机名登录了</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598199538528.png" alt="1598199538528"></p><h3 id="_13-4-3-ssh基于秘钥实现免密登录" tabindex="-1">13.4.3 ssh基于秘钥实现免密登录 <a class="header-anchor" href="#_13-4-3-ssh基于秘钥实现免密登录" aria-label="Permalink to &quot;13.4.3 ssh基于秘钥实现免密登录&quot;">​</a></h3><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598200099761.png" alt="1598200099761"></p><p>前提：配置hostname与IP映射 第一步：在三台机器器执行行以下命令，生成公钥与私钥</p><p>第二步：将centos7-2和centos7-3的公钥拷贝到centos7-1</p><p>第三步：再将centos7-1的公钥分发给centos7-2和centos7-3</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	第一步:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ssh-keygen</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -t</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> rsa</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">  在centos7-1和centos7-2和centos7-3上面都要执行，产生公钥和私钥</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	第二步：在centos7-1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ,centos7-2和centos7-3上执行:</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			ssh-copy-id</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> centos7-1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 将公钥拷贝到centos7-1上面去</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	第三步：</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			scp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> authorized_keys</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> centos7-2:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$PWD</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">			scp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> authorized_keys</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> centos7-3:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$PWD</span></span></code></pre></div><p>使用ssh完成免密登录即可 （ssh centos7-2）</p><h2 id="_13-5-三台机器时钟同步" tabindex="-1">13.5 三台机器时钟同步 <a class="header-anchor" href="#_13-5-三台机器时钟同步" aria-label="Permalink to &quot;13.5 三台机器时钟同步&quot;">​</a></h2><h3 id="_13-5-1-原理" tabindex="-1">13.5.1 原理 <a class="header-anchor" href="#_13-5-1-原理" aria-label="Permalink to &quot;13.5.1 原理&quot;">​</a></h3><p>内网的所有服务器都和时钟服务器进行同步时间</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1604568014037.png" alt="1534477026131"></p><h3 id="_13-5-2-如何同步" tabindex="-1">13.5.2 如何同步 <a class="header-anchor" href="#_13-5-2-如何同步" aria-label="Permalink to &quot;13.5.2  如何同步&quot;">​</a></h3><ol><li>查看本机当前时间</li></ol><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>date</span></span></code></pre></div><ol start="2"><li>设置本机当前时间</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">date</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;2018-08-17 20:08:09&quot;</span></span></code></pre></div><ol start="3"><li>通过命名和时钟服务器同步时间:</li></ol><p>网络计时协议（NTP） : net time protocal</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ntpdate</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> us.pool.ntp.org</span></span></code></pre></div><ol start="4"><li>编辑定时任务</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">crontab</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -e</span></span></code></pre></div><ol><li>定时任务内容如下</li></ol><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /usr/sbin/ntpdate us.pool.ntp.org;</span></span></code></pre></div><p>每隔1分钟执行指令一次</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598208410721.png" alt="1598207273496"></p><p>Crontab使用</p><p>格式说明</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Example of job definition:</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># .---------------- minute (0 - 59)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># |  .------------- hour (0 - 23)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># |  |  .---------- day of month (1 - 31)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># |  |  |  |  |</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># *  *  *  *  * user-name  command to be executed</span></span></code></pre></div><p>使用实例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">实例1：每1分钟执行一次command</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">命令：*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">实例2：每小时的第3和第15分钟执行</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">命令：3,15</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">实例3：在上午8点到11点的第3和第15分钟执行</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">命令：3,15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8-11</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">实例4：每隔两天的上午8点到11点的第3和第15分钟执行</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">命令：3,15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8-11</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">实例5：每个星期一的上午8点到11点的第3和第15分钟执行</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">命令：3,15</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 8-11</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> command</span></span></code></pre></div><blockquote><h4 id="crantab在线生成" tabindex="-1">Crantab在线生成 <a class="header-anchor" href="#crantab在线生成" aria-label="Permalink to &quot;Crantab在线生成&quot;">​</a></h4><p><a href="https://cron.qqe2.com/" target="_blank" rel="noreferrer">https://cron.qqe2.com/</a></p></blockquote><h1 id="第14章-shell编程" tabindex="-1">第14章 Shell编程 <a class="header-anchor" href="#第14章-shell编程" aria-label="Permalink to &quot;第14章  Shell编程&quot;">​</a></h1><h2 id="_14-1-简介" tabindex="-1">14.1 简介 <a class="header-anchor" href="#_14-1-简介" aria-label="Permalink to &quot;14.1 简介&quot;">​</a></h2><p>​ Linux中的shell脚本是一个特殊的应用程序，它介于操作系统和系统内核之间，充当一个命令解释器的角色。负责接收用户输入的操作指令并进行解释，将需要执行的操作传递给内核执行，并输出执行结果。 同时它又是一种程序设计语言。作为命令语言，它交互式解释和执行用户输入的命令或者自动地解释和执行预先设定好的一连串的命令；作为程序设计语言，它定义了各种变量和参数，并提供了许多在高级语言中才具有的控制结构，包括循环和分支。 Linux 的 Shell 解释器 种类众多，一个系统可以存在多个 shell，可以通过 cat /etc/shells 命令查看系统中安装的 shell解释器。 Bash 由于易用和免费，在日常工作中被广泛使用。同时，Bash 也是大多数Linux 系统默认的 Shell。</p><h2 id="_14-2-shell-解释器" tabindex="-1">14.2 shell 解释器 <a class="header-anchor" href="#_14-2-shell-解释器" aria-label="Permalink to &quot;14.2 shell 解释器&quot;">​</a></h2><p>java 需要 虚拟机解释器, 同理 shell脚本也需要 解析器</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@node04 shells]# cat /etc/shells</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/bin/sh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/sbin/nologin</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/bin/dash</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/bin/tcsh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/bin/csh</span></span></code></pre></div><h2 id="_14-3-快速入门" tabindex="-1">14.3 快速入门 <a class="header-anchor" href="#_14-3-快速入门" aria-label="Permalink to &quot;14.3 快速入门&quot;">​</a></h2><h3 id="_14-3-1-编写脚本" tabindex="-1">14.3.1 编写脚本 <a class="header-anchor" href="#_14-3-1-编写脚本" aria-label="Permalink to &quot;14.3.1 编写脚本&quot;">​</a></h3><p>新建 /usr/shell/hello.sh 文件</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;hello lagou&#39;</span></span></code></pre></div><p>!是一个约定的标记，它告诉系统这个脚本需要什么解释器来执行，即使用哪一种 Shell。</p><p>echo 命令用于向窗口输出文本。</p><h3 id="_14-3-2-执行shell脚本" tabindex="-1">14.3.2 执行shell脚本 <a class="header-anchor" href="#_14-3-2-执行shell脚本" aria-label="Permalink to &quot;14.3.2 执行shell脚本&quot;">​</a></h3><p><strong>执行方式1</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@centos7-1 shell]# /bin/sh hello.sh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lagou</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@centos7-1 shell]# /bin/bash hello.sh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> lagou</span></span></code></pre></div><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1598261904924.png" alt="1598261904924"></p><p>问题: bash 和 sh 是什么关系?</p><p><code>sh 是 bash 的 快捷方式</code></p><p><strong>执行方式2</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@node04 shells]# bash hello.sh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> world</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@node04 shells]# sh hello.sh</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">hello</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> world</span></span></code></pre></div><blockquote><p>1.查看环境变量path:</p><p>echo $PATH</p><p>2.添加执行权限</p><p>chmod +x 文件名称</p></blockquote><h2 id="_14-4-变量" tabindex="-1">14.4 变量 <a class="header-anchor" href="#_14-4-变量" aria-label="Permalink to &quot;14.4 变量&quot;">​</a></h2><p>在shell脚本中, 定义变量时，变量名不加美元符号（$），如： <code>username=&quot;tom&quot;</code></p><p>注意 : 变量名和等号之间不能有空格，这可能和你熟悉的所有编程语言都不一样。 同时，变量名的命名须遵循如下规则：</p><ul><li>命名只能使用英文字母，数字和下划线，首个字符不能以数字开头。</li><li>中间不能有空格，可以使用下划线（_）。</li><li>不能使用标点符号。</li><li>不能使用bash里的关键字（可用help命令查看保留关键字）。</li></ul><p>有效的 Shell 变量名示例如下：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">JACK</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">LD_LIBRARY_PATH</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">_demo</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">var2</span></span></code></pre></div><p>无效的变量命名：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">?</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">var</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">123</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">user*name</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">=runoob</span></span></code></pre></div><p>使用语句给变量赋值</p><p>举例:</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> file </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in`</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ls </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">etc</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">`</span></span></code></pre></div><p>或</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> file </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p>以上语句是将/etc下目录的文件名循环出来</p><p><strong>使用变量</strong></p><p>使用一个定义过的变量，只要在变量名前面加美元符号即可，如：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">your_name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;tom&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $your_name</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ${your_name}</span></span></code></pre></div><p>变量名外面加花括号是可选的, 添加花括号是帮助解释器识别变量边界</p><p>举例:</p><div class="language-powershell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">habby</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;i like </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">${course}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">script&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">habby</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;i like </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$coursescript</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span></code></pre></div><p><strong>只读变量</strong></p><p>使用readyonly命令可以将变量定义为只读变量, 只读变量的值不能被改变</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">readonly</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">  变量名</span></span></code></pre></div><p>举例:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">username</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">tom</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">readonly</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> username</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">username</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">jack</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> 报错</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">   /bin/sh:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> NAME:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> This</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> variable</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> is</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> read</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> only.</span></span></code></pre></div><p><strong>删除变量</strong></p><p>使用unset命令可以删除变量</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">unset</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> variable_name</span></span></code></pre></div><p>注意:unset命令不能删除只读变量</p><h2 id="_14-5-字符串" tabindex="-1">14.5 字符串 <a class="header-anchor" href="#_14-5-字符串" aria-label="Permalink to &quot;14.5 字符串&quot;">​</a></h2><p>字符串是shell编程中最常用最有用的数据类型（除了数字和字符串，也没啥其它类型好用了），字符串可以用单 引号，也可以用双引号，也可以不用引号。</p><p><strong>单引号</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skill</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;java&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;I am goot at $skill&#39;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $str</span></span></code></pre></div><p>输出结果为:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> am</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> goot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> at</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $skill</span></span></code></pre></div><p>单引号字符串的限制：</p><ul><li><p>单引号里的任何字符都会原样输出，单引号字符串中的变量是无效的；</p></li><li><p>单引号字串中不能出现单独一个的单引号（对单引号使用转义符后也不行）</p></li></ul><p><strong>双引号</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skill</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;java&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;I am goot at </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$skill</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $str</span></span></code></pre></div><p>输出结果为：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> am</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> goot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> at</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> java</span></span></code></pre></div><p>双引号的优点：</p><ul><li>双引号里可以有变量</li><li>双引号里可以出现转义字符</li></ul><p><strong>获取字符串长度</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skill</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;java&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ${skill} </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 输出结果: java</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ${</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">skill} </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 输出结果: 4</span></span></code></pre></div><p><strong>提取子字符串</strong></p><p>一下实例从字符串第2个字符开始截取4个字符</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;i like hadoop&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ${str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">2}  </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#substring(2)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ${str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">2}   </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#substring(2,2)</span></span></code></pre></div><p><strong>查找子字符串</strong></p><p>查找字符o在那个位置(最先出现的字符)</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">str</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;hadoop is so easy&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> `</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">expr</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> index &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$str</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot; o`</span></span></code></pre></div><p>找的时候是从1开始查找</p><h2 id="_14-6-运算符" tabindex="-1">14.6 运算符 <a class="header-anchor" href="#_14-6-运算符" aria-label="Permalink to &quot;14.6 运算符&quot;">​</a></h2><p>Shell 和其他编程一样，支持包括：算术、关系、布尔、字符串等运算符。原生 bash 不支持 简单的数学运算，但是可以通过其他命令来实现，例如expr。expr 是一款表达式计算工具，使用它能完成表达式的求值操作。 例如，两个数相加</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">val</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">`</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">expr</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">`</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $val</span></span></code></pre></div><p>注意：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>表达式和运算符之间要有空格，例如 1+2 是不对的，必须写成 1 + 2。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>完整的表达式要被 ` 包含，注意不是单引号，在 Esc 键下边。</span></span>
<span class="line"><span></span></span>
<span class="line"><span>下表列出了常用的算术运算符，假定变量 a 为 10，变量 b 为 20：</span></span></code></pre></div><h3 id="_14-6-1-算数运算符" tabindex="-1">14.6.1 算数运算符<img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592733302241.png" alt="1592733302241"> <a class="header-anchor" href="#_14-6-1-算数运算符" aria-label="Permalink to &quot;14.6.1 算数运算符![1592733302241](https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592733302241.png)&quot;">​</a></h3><p>注意：条件表达式要放在方括号之间，并且要有空格，例如: <code>[$a==$b]</code>是错误的，</p><p>必须写成<code> [ $a == $b ]</code>。</p><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">4</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">20</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#加法运算</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">each</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> expr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $a </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#减法运算</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> expr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $a </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#乘法运算，注意*号前面需要反斜杠</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> expr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $a </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#除法运算</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $a </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">此外，还可以通过((</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">))、$(())、$[]进行算术运算。</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">((a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">++</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">))</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;a = </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">c</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$((</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">))</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">d</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[a</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> b]</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;c = </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;d = </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span></code></pre></div><h3 id="_14-6-2-关系运算符" tabindex="-1">14.6.2 关系运算符 <a class="header-anchor" href="#_14-6-2-关系运算符" aria-label="Permalink to &quot;14.6.2 关系运算符&quot;">​</a></h3><p>关系运算符只支持数字，不支持字符串，除非字符串的值是数字。 下表列出了常用的关系运算符，假定变量 a 为 10，变量 b 为 20：</p><p><img src="https://typora5672.oss-cn-chengdu.aliyuncs.com/temp/1592733486805.png" alt="1592733486805"></p><h2 id="_14-7-流程控制" tabindex="-1">14.7 流程控制 <a class="header-anchor" href="#_14-7-流程控制" aria-label="Permalink to &quot;14.7 流程控制&quot;">​</a></h2><h3 id="_14-7-1-if语句" tabindex="-1">14.7.1 if语句 <a class="header-anchor" href="#_14-7-1-if语句" aria-label="Permalink to &quot;14.7.1 if语句&quot;">​</a></h3><ul><li>if语句格式</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> condition</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command2</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    ...</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    commandN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span></code></pre></div><ul><li>if.else语句</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> condition</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command2</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    ...</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    commandN</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    command</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span></code></pre></div><ul><li>if..elif..else</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> condition1</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command1</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">elif</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> condition2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    command2</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    commandN</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span></code></pre></div><p>案例</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@hadoop01 export]# cat if_test.sh</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">20</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">10</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求1: 判断 a 是否 100</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 大于 100&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求2: 判断 a 是否等于 b</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-eq</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 等于 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 不等于 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求3: 判断 a 与 b 比较</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-lt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 小于 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-eq</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $b ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 等于 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 大于 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求4: 判断 (a + 10) 和 (b * b) 比较大小</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> test</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -gt</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> b</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> *</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;(a+10) 大于 (b * b)&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;(a+10) 小于或等于 (b*b)&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">fi</span></span></code></pre></div><h3 id="_14-7-2-for-循环" tabindex="-1">14.7.2 for 循环 <a class="header-anchor" href="#_14-7-2-for-循环" aria-label="Permalink to &quot;14.7.2 for 循环&quot;">​</a></h3><p>格式</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> variable </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">list</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">); </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">command</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">command</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><p>练习</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span># 需求1: 遍历 1~5</span></span>
<span class="line"><span># 需求2: 遍历 1~100</span></span>
<span class="line"><span># 需求3: 遍历 1~100之间的奇数</span></span>
<span class="line"><span># 需求4: 遍历 根目录 下的内容</span></span></code></pre></div><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[root@hadoop01 export]# cat for_test.sh</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求1: 遍历 1~5</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 4</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 5</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $i;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求2: 遍历 1~100</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1..100}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $i</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求3: 遍历 1~100之间的奇数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1..100..2}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $i</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求4: 遍历 根目录 下的内容</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> f </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> `</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /`</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $f</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><h3 id="_14-7-3-while-语句" tabindex="-1">14.7.3 while 语句 <a class="header-anchor" href="#_14-7-3-while-语句" aria-label="Permalink to &quot;14.7.3 while 语句&quot;">​</a></h3><p>while循环用于不断执行一系列命令，也用于从输入文件中读取数据；命令通常为测试条件。其格式为</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> condition</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	command</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><p>需求: 计算 1~100 的和</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">sum</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">1</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-le</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	sum</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sum</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> i]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $sum</span></span></code></pre></div><p>运行脚本，输出：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>5050</span></span></code></pre></div><h3 id="_14-7-4-无限循环" tabindex="-1">14.7.4 无限循环 <a class="header-anchor" href="#_14-7-4-无限循环" aria-label="Permalink to &quot;14.7.4 无限循环&quot;">​</a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ((;;))</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">      command</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> true</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    command</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><h2 id="_14-8-case" tabindex="-1">14.8 case <a class="header-anchor" href="#_14-8-case" aria-label="Permalink to &quot;14.8 case&quot;">​</a></h2><p>Shell case语句为多选择语句。可以用case语句匹配一个值与一个模式，如果匹配成功，执行相匹配的命令。case 语句格式如下：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> 值 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	模式1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		command1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		command2</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		...</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		commandN</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	模式2）</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">		command1</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">		command2</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">		...</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">		commandN</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">		;;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">esac</span></span></code></pre></div><p>case工作方式如上所示。取值后面必须为单词in，每一模式必须以右括号结束。取值可以为变量或常数。匹配发现 取值符合某一模式后，其间所有命令开始执行直至 ;;。 取值将检测匹配的每一个模式。一旦模式匹配，则执行完匹配模式相应命令后不再继续其他模式。如果无一匹配模 式，使用星号 * 捕获该值，再执行后面的命令。 下面的脚本提示输入1到4，与每一种模式进行匹配：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;输入 1 到 4 之间的数字:&#39;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">read</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> aNum</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $aNum </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;你选择了 1&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;你选择了 2&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	3</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;你选择了 3&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">	4</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;你选择了 4&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">	*)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;你没有输入 1 到 4 之间的数字&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">esac</span></span></code></pre></div><p>输入不同的内容，会有不同的结果，例如：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>输入 1 到 4 之间的数字:</span></span>
<span class="line"><span>你输入的数字为:</span></span>
<span class="line"><span>3</span></span>
<span class="line"><span>你选择了 3</span></span></code></pre></div><h2 id="_14-9-跳出循环" tabindex="-1">14.9 跳出循环 <a class="header-anchor" href="#_14-9-跳出循环" aria-label="Permalink to &quot;14.9 跳出循环&quot;">​</a></h2><p>在循环过程中，有时候需要在未达到循环结束条件时强制跳出循环，Shell使用两个命令来实现该功能：break和 continue。</p><h3 id="_14-9-1-break命令" tabindex="-1">14.9.1 break命令 <a class="header-anchor" href="#_14-9-1-break命令" aria-label="Permalink to &quot;14.9.1  break命令&quot;">​</a></h3><p>break命令允许跳出所有循环（终止执行后面的所有循环）。</p><p>需求: 执行死循环 每隔1秒打印当前时间, 执行10次停止</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求: 执行死循环 每隔1秒打印当前时间, 执行10次停止</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">		sleep</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">		echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $i </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">`</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">date</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +&quot;%Y-%m-%d %H:%M:%S&quot;`</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">		i</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">		if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-eq</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">			break</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">		fi</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><h3 id="_14-9-2-continue" tabindex="-1">14.9.2 continue <a class="header-anchor" href="#_14-9-2-continue" aria-label="Permalink to &quot;14.9.2 continue&quot;">​</a></h3><p>continue命令与break命令类似，只有一点差别，它不会跳出所有循环，仅仅跳出当前循环。</p><p>需求: 打印 1~30, 注意 跳过3的倍数</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 需求: 打印 1~30, 注意 跳过3的倍数</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">1..30}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">	if</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> test</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> %</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ]</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -eq</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">		continue</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">	fi</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $i</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><h2 id="_14-10-函数使用" tabindex="-1">14.10 函数使用 <a class="header-anchor" href="#_14-10-函数使用" aria-label="Permalink to &quot;14.10 函数使用&quot;">​</a></h2><h3 id="_14-10-1-函数的快速入门" tabindex="-1">14.10.1 函数的快速入门 <a class="header-anchor" href="#_14-10-1-函数的快速入门" aria-label="Permalink to &quot;14.10.1 函数的快速入门&quot;">​</a></h3><p>格式</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[ function ] </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">funname</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	action</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	[return int;]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><ul><li><p>可以带function fun() 定义，也可以直接fun() 定义,不带任何参数。</p></li><li><p>参数返回，可以显示加：return 返回，如果不加，将以最后一条命令运行结果，作为返回值。 return后</p><p><strong>跟数值n(0-255)</strong></p></li></ul><p><strong>快速入门</strong></p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">demoFun</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;这是我的第一个 shell 函数!&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;-----函数开始执行-----&quot;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">demoFun</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;-----函数执行完毕-----&quot;</span></span></code></pre></div><h3 id="_14-10-2-传递参数给函数" tabindex="-1">14.10.2 传递参数给函数 <a class="header-anchor" href="#_14-10-2-传递参数给函数" aria-label="Permalink to &quot;14.10.2 传递参数给函数&quot;">​</a></h3><p>在Shell中，调用函数时可以向其传递参数。在函数体内部，通过 $n 的形式来获取参数的值，例如，$1表示第一个 参数，$2表示第二个参数... 带参数的函数示例：</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">funWithParam</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;第一个参数为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">$1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;第二个参数为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">$2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;第十个参数为 </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$10</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;第十个参数为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">${10}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;第十一个参数为 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">${11}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;参数总数有 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">$#</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 个!&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;作为一个字符串输出所有参数 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">$*</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> !&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">funWithParam</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 4</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 5</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 6</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 7</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 9</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 34</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 73</span></span></code></pre></div><p>输出结果：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>第一个参数为 1 !</span></span>
<span class="line"><span>第二个参数为 2 !</span></span>
<span class="line"><span>第十个参数为 10 !</span></span>
<span class="line"><span>第十个参数为 34 !</span></span>
<span class="line"><span>第十一个参数为 73 !</span></span>
<span class="line"><span>参数总数有 11 个!</span></span>
<span class="line"><span>作为一个字符串输出所有参数 1 2 3 4 5 6 7 8 9 34 73 !</span></span></code></pre></div><h2 id="_14-11-shell编程案例" tabindex="-1">14.11 shell编程案例 <a class="header-anchor" href="#_14-11-shell编程案例" aria-label="Permalink to &quot;14.11 shell编程案例&quot;">​</a></h2><h3 id="_14-11-1-统计目录文件" tabindex="-1">14.11.1 统计目录文件 <a class="header-anchor" href="#_14-11-1-统计目录文件" aria-label="Permalink to &quot;14.11.1 统计目录文件&quot;">​</a></h3><p>编写脚本/root/bin/sumfile.sh，统计/etc，/var，/usr目录中共有多少个一级子目录和文件</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">##写一个脚本/root/bin/sumfile.sh,统计/etc, /var, /usr目录中共有多少个一级子目录和文件</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /var</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num3</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">ls</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -l</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">let</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Num=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$num1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$num2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$num3</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $Num</span></span></code></pre></div><p>​</p><h3 id="_14-11-2-猜数字小游戏" tabindex="-1">14.11.2 猜数字小游戏 <a class="header-anchor" href="#_14-11-2-猜数字小游戏" aria-label="Permalink to &quot;14.11.2 猜数字小游戏&quot;">​</a></h3><p>脚本生成一个 100 以内的随机数字，提示用户才数字，根据用户的输入，提示用户是否猜对， 猜大或猜小继续循环猜，猜对跳出循环。 RANDOM 为系统自动的系统变量，值为 0-32767 的随机数</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#猜数字小游戏</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">num</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">[RANDOM%100+1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> :</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        read</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;计算机生成一个1-100的随机数&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cat</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $cat </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-eq</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $num ];</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;猜对了&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">                break</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $cat </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-le</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $num ];</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">then</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;小了&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        else</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;大了&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">       fi</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div><h3 id="_14-11-3-使用-case、-while-和-read-进行查看磁盘信息" tabindex="-1">14.11.3 使用 case、 while 和 read 进行查看磁盘信息 <a class="header-anchor" href="#_14-11-3-使用-case、-while-和-read-进行查看磁盘信息" aria-label="Permalink to &quot;14.11.3 使用 case、 while 和 read 进行查看磁盘信息&quot;">​</a></h3><p>题目：编写一个交互脚本，执行脚本时候键盘输入对应的参数，脚本反馈对应信息，当输入 为“exit”时候脚本退出。脚本采用 read 捕捉键盘输入信息，然后使用 case 进行条件选择并执行命令，最 后使用 while 对 case 语句进行循环。</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#!/bin/bash</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#EOF (End Of File)表示文本结束符。注意: EOF必须顶行写，前面不能用制表符或者空格。</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#cat &lt;&lt; EOF的意思是以EOF输入字符为标准输入结束，就是当你输入cat &lt;&lt; EOF的时候，你可以随意输入字符，但是当输入EOF#的时候就结束了</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cat</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;&lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> EOF</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">D|d 显示硬盘信息</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">M|m 显示内存信息</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">S|s 显示交换分区信息</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">EOF</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">read</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;请输入以上对应参数:&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> CANSHU</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">while</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ $CANSHU </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;exit&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ]; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">do</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">case</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $CANSHU </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">d</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">D</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	df</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -h</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">m</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">M</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	free</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -m</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> grep</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Mem</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">s</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">|</span><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;">S</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	free</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -m</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> grep</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Swap</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*)</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">	echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Ukown&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	;;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">esac</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">read</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -p</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;请再次输入以上对应参数:&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> CANSHU</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">done</span></span></code></pre></div></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-e257564d><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e257564d><span class="visually-hidden" id="doc-footer-aria-label" data-v-e257564d>Pager</span><div class="pager" data-v-e257564d><!----></div><div class="pager" data-v-e257564d><a class="VPLink link pager-link next" href="/Linux/%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9B%B8%E5%85%B3.html" data-v-e257564d><!--[--><span class="desc" data-v-e257564d>下一篇</span><span class="title" data-v-e257564d>虚拟机相关</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2024.8.15-present 九问.All Rights Reserved.</p></div></footer><!--[--><!--]--></div><!----><!----><!--]--></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"index.md\":\"DPLzomJ3\",\"linux_linux基础入门.md\":\"pHBVwgKW\",\"linux_常用命令备忘.md\":\"BjZbNsQB\",\"linux_虚拟机相关.md\":\"509DUbJA\",\"llm_langchain_lcel表达式与runnable可运行协议.md\":\"Do8svL8L\",\"llm_langchain_model.md\":\"BseancJn\",\"llm_langchain_outputparser.md\":\"Dy6NsY5B\",\"llm_langchain_prompt.md\":\"XqZSAhnf\",\"llm_langchain_quick_start.md\":\"BNcILzfr\",\"python_原理类_依赖注入.md\":\"CL2SMX95\",\"python_原理类_内存管理.md\":\"CPaxdydH\",\"python_原理类_单例模式.md\":\"sMUaVqEG\",\"python_原理类_多进程多线程协程.md\":\"DqpQdOiz\",\"python_原理类_深浅拷贝.md\":\"CLyf8bhf\",\"python_原理类_自省.md\":\"xlfwK7Qt\",\"python_原理类_迭代器和生成器.md\":\"CkWqBBDs\",\"python_原理类_闭包和装饰器.md\":\"DK3E-cjV\",\"python_原理类_高阶函数.md\":\"DCh-efV4\",\"python_原理类_魔法方法.md\":\"DmwyLFne\",\"python_原理类_鸭子类型.md\":\"5JGfCqIC\",\"python_基础_练习题.md\":\"CsgELmqe\",\"python_工具类_logging.md\":\"dWLhofea\",\"python框架_django_4-1环境搭建.md\":\"B6koVIdo\",\"python框架_django_4-2settings配置.md\":\"B6f707F-\",\"python框架_django_4-3路由定义与使用.md\":\"BD3-Rmv3\",\"python框架_django_4-4请求与响应.md\":\"n_ivviS2\",\"python框架_django_4-5session_cookie.md\":\"DAeZMmLC\",\"python框架_django_4-6类视图.md\":\"CC_0FUMu\",\"python框架_django_4-7模板引擎.md\":\"BdpQJw0a\",\"python框架_django_接口文档.md\":\"cRd_13f9\",\"python框架_django_熟悉流程_部署博客.md\":\"B4LDDwJF\",\"python框架_django_虚拟环境.md\":\"CANoJLNU\",\"python框架_flask_flask-sqlalchemy.md\":\"CUU_aFQd\",\"python框架_flask_flask-wtf_wtfforms.md\":\"LvJO-ZqI\",\"python框架_flask_start.md\":\"CEtxJVgY\",\"其他_八股_linux.md\":\"CJveVc64\",\"其他_八股_其他_汇编_串指令.md\":\"BttYJMTr\",\"其他_八股_其他_汇编_前置知识.md\":\"BucxfzEY\",\"其他_八股_其他_汇编_宏汇编.md\":\"2UfLWMAK\",\"其他_八股_其他_汇编_寄存器.md\":\"jp1xBRVS\",\"其他_八股_其他_汇编_寻址方式.md\":\"CewV_a8e\",\"其他_八股_其他_汇编_数据传送指令.md\":\"PY1RmkQj\",\"其他_八股_其他_汇编_程序设计综合.md\":\"CqsM9zoN\",\"其他_八股_其他_汇编_逻辑运算与移位指令.md\":\"B_-kKKiB\",\"其他_八股_其他_网安_网络安全.md\":\"COiOJXPx\",\"其他_八股_前端_css_单位.md\":\"DyaFOJT4\",\"其他_八股_前端_css_居中的方式.md\":\"rsk20pg5\",\"其他_八股_前端_html_文档声明.md\":\"CQQLsheK\",\"其他_八股_前端_html_替换元素.md\":\"D69yt3g4\",\"其他_八股_前端_html_语义化_seo_微格式.md\":\"DcyemF8i\",\"其他_八股_前端_html_页面可见性.md\":\"CFWJeBWr\",\"其他_八股_前端_事件循环_异步.md\":\"pX3ui26Y\",\"其他_八股_操作系统_存储管理.md\":\"BiNbZ62S\",\"其他_八股_操作系统_操作系统安全及虚拟化技术概述.md\":\"JHACDhW4\",\"其他_八股_操作系统_操作系统概述及基本概念.md\":\"D9Lo515v\",\"其他_八股_操作系统_文件系统.md\":\"Dtjdw_je\",\"其他_八股_操作系统_死锁.md\":\"zHFIU7qo\",\"其他_八股_操作系统_输入输出.md\":\"frvtHq-m\",\"其他_八股_操作系统_进程与线程.md\":\"DbHOm3Wq\",\"其他_八股_操作系统_面试八股.md\":\"CzgRxFHm\",\"其他_八股_数据库_log.md\":\"B-ybS9bR\",\"其他_八股_数据库_mysql的执行引擎.md\":\"CUp82kj5\",\"其他_八股_数据库_redis.md\":\"z8vp5n46\",\"其他_八股_数据库_sql语句的执行.md\":\"B0aqkw_M\",\"其他_八股_数据库_事务_事务的四大特性.md\":\"DWegFK6Q\",\"其他_八股_数据库_事务_事务的隔离级别.md\":\"CJpAB-SH\",\"其他_八股_数据库_慢查询.md\":\"C1IK6Wix\",\"其他_八股_数据库_索引失效的场景.md\":\"Ax0k9vQn\",\"其他_八股_数据库_进阶_窗口函数.md\":\"C_zDFJPI\",\"其他_八股_数据结构_二分法.md\":\"cV9m7f2a\",\"其他_八股_数据结构_二叉树.md\":\"DkYu-9Db\",\"其他_八股_数据结构_回溯.md\":\"CcyoEaKv\",\"其他_八股_数据结构_数组_蛇形填数.md\":\"sJgKru0T\",\"其他_八股_数据结构_滑动窗口最大值.md\":\"7EhHWPLR\",\"其他_八股_数据结构_背包_01背包.md\":\"Bm-yOyBt\",\"其他_八股_数据结构_链表_两两交换链表中的节点.md\":\"B8MvoYxB\",\"其他_八股_数据结构_链表_单链表.md\":\"BrcntfvU\",\"其他_八股_数据结构_链表_反转链表.md\":\"imXNe7Cp\",\"其他_八股_测开_bug.md\":\"DEH0Pngz\",\"其他_八股_测开_性能测试.md\":\"BIq1PtDn\",\"其他_八股_测开_测试的流程.md\":\"BDpHuwv1\",\"其他_八股_测开_测试的理解.md\":\"D0oj3MOT\",\"其他_八股_测开_软件测试.md\":\"DBQvBkbe\",\"其他_八股_测开_软件质量.md\":\"BbbVdNmM\",\"其他_八股_计网_cdn.md\":\"BBkFV3YX\",\"其他_八股_计网_cookie_session.md\":\"9lTHujdv\",\"其他_八股_计网_dns查询过程.md\":\"UEG8MFOS\",\"其他_八股_计网_http常见状态码.md\":\"FjHGrHsS\",\"其他_八股_计网_osi模型.md\":\"CQQrgYYo\",\"其他_八股_计网_url到页面展示.md\":\"CysFBpDy\",\"其他_八股_计网_传输层_tcp_udp.md\":\"CGN96CrC\",\"其他_八股_计网_应用层_http.md\":\"BwfPa-_I\",\"其他_八股_计网_应用层_http1.0各个版本.md\":\"Po_QFcD7\",\"其他_八股_计网_应用层_http_https.md\":\"CVNCJSvP\",\"其他_八股_计网_强缓存和协商缓存.md\":\"BCS9u_As\",\"其他_八股_计网_物理层_奈氏准则_香农公式.md\":\"LJ2m6SOu\",\"其他_面经_大疆.md\":\"7GCAKeVb\",\"其他_面经_差旅1号.md\":\"COJ0oCTe\",\"其他_面经_广州嘉为科技公司-python.md\":\"DKqZln1v\",\"其他_面经_得物.md\":\"Dh7JuSj9\",\"其他_面经_招商银行.md\":\"xRFKUhWx\",\"其他_面经_百度.md\":\"BNUT_qAS\",\"其他_项目_项目部署_vitepress_githubpages部署.md\":\"BVpDdxkG\",\"其他_项目_项目部署_vitepress_netlify部署.md\":\"Coqp4VTV\",\"其他_项目_项目部署_vitepress_nginx部署.md\":\"BAeOv9Kq\",\"其他_项目_项目部署_web.md\":\"BoGi1t8O\",\"前端_vue3_axios.md\":\"D33GJUpk\",\"前端_vue3_面试.md\":\"Ba2Ot3Rt\",\"前端_前端三件套_css_css3自定义属性.md\":\"D8gxja-i\",\"前端_前端三件套_css_css基础入门.md\":\"ndtMtB1o\",\"前端_前端三件套_css_flexbox布局.md\":\"THfIflcE\",\"前端_前端三件套_css_grid布局.md\":\"DxVJntk3\",\"前端_前端三件套_css_动画.md\":\"CFLVIA4-\",\"前端_前端三件套_css_媒体查询.md\":\"DOMiDDiY\",\"前端_前端三件套_css_属性.md\":\"CESPzocp\",\"前端_前端三件套_html_html基础.md\":\"DVzBORCM\",\"前端_前端三件套_js_dom操作.md\":\"DMHjLETt\",\"前端_前端三件套_js_js入门.md\":\"B5ZmIMru\",\"前端_前端三件套_js_属性描述符.md\":\"CbnoBHiZ\",\"前端_前端三件套_js_高阶函数.md\":\"xnE4baNa\",\"前端_前端三件套_实战案例_聊天页面.md\":\"Biaa-glg\",\"前端_前端三件套_面试_基本题.md\":\"CHZnvxX-\",\"工具_git_gitignore.md\":\"DoXDP0e-\",\"工具_git_git的基本使用.md\":\"DU6wlewG\",\"工具_git_同时推送gitee和github.md\":\"Cvg2MFU1\",\"测试_faker数据随机生成.md\":\"BasZvW7O\",\"测试_jenkins.md\":\"CFQxIQZz\",\"测试_pytest_pytest基础.md\":\"6gYMEMqz\",\"测试_pytest_yaml文件.md\":\"kC0gde-v\",\"测试_pytest_日志.md\":\"CXf5niRD\",\"测试_unittest.md\":\"DLCFrt8V\",\"测试_性能测试_基础概念.md\":\"DOav1Wqa\",\"爬虫_bs4解析.md\":\"DuOzYyCe\",\"爬虫_jsonpath解析.md\":\"Drhtc37w\",\"爬虫_scrapy.md\":\"D83vZHmx\",\"爬虫_selenium.md\":\"BhDk9UyV\",\"爬虫_xpath解析.md\":\"MjtoQ3qX\",\"爬虫_导论.md\":\"BiquNqIP\",\"爬虫_抓包.md\":\"BDJtadra\",\"爬虫_登录流程.md\":\"MPghsp8c\",\"环境搭建_docker_mysql.md\":\"Duy1yYHv\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"九问Blog\",\"description\":\"欢迎访问九问Blog！分享一些Python全栈开发以及爬虫技术，希望对你有所帮助\",\"base\":\"/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/jiuwen567\"},{\"icon\":{\"svg\":\"<svg t=\\\"1724307958358\\\" class=\\\"icon\\\" viewBox=\\\"0 0 1024 1024\\\" version=\\\"1.1\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" p-id=\\\"4234\\\" width=\\\"200\\\" height=\\\"200\\\"><path d=\\\"M512 0C230.4 0 0 230.4 0 512s230.4 512 512 512 512-230.4 512-512S793.6 0 512 0z m284.8 313.6c0 12.8-12.8 25.6-25.6 25.6H416c-41.6 0-76.8 35.2-76.8 76.8v243.2c0 12.8 12.8 25.6 25.6 25.6h240c41.6 0 76.8-35.2 76.8-76.8v-12.8c0-12.8-12.8-25.6-25.6-25.6H480c-12.8 0-25.6-12.8-25.6-25.6v-64c0-12.8 12.8-25.6 25.6-25.6h291.2c12.8 0 25.6 12.8 25.6 25.6v144c0 92.8-76.8 169.6-169.6 169.6H252.8c-12.8 0-25.6-12.8-25.6-25.6V412.8C227.2 310.4 310.4 224 416 224h355.2c12.8 0 25.6 12.8 25.6 25.6v64z\\\" fill=\\\"#B32225\\\" p-id=\\\"4235\\\"></path></svg>\"},\"link\":\"https://gitee.com/jiuwen567\"}],\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2024.8.15-present 九问.All Rights Reserved.\"},\"search\":{\"provider\":\"local\"},\"docFooter\":{\"prev\":\"上一篇\",\"next\":\"下一篇\"},\"returnToTopLabel\":\"回到顶部\",\"sidebarMenuLabel\":\"菜单\",\"darkModeSwitchLabel\":\"主题\",\"lightModeSwitchTitle\":\"切换到浅色模式\",\"darkModeSwitchTitle\":\"切换到深色模式\",\"nav\":[{\"text\":\"工具\",\"activeMatch\":\"/工具/\",\"link\":\"/工具/Git/同时推送Gitee和GitHub\"},{\"text\":\"Linux\",\"activeMatch\":\"/Linux/\",\"link\":\"/Linux/Linux基础入门\"},{\"text\":\"爬虫\",\"activeMatch\":\"/爬虫/\",\"link\":\"/爬虫/导论\"},{\"text\":\"测试\",\"activeMatch\":\"/测试/\",\"link\":\"/测试/faker数据随机生成\"},{\"text\":\"Python\",\"activeMatch\":\"/Python/\",\"link\":\"/Python/原理类/内存管理\"},{\"text\":\"Python框架\",\"activeMatch\":\"/Python框架/\",\"link\":\"/Python框架/Django/接口文档\"},{\"text\":\"其他\",\"activeMatch\":\"/其他/\",\"link\":\"/其他/八股/Linux\"},{\"text\":\"前端\",\"activeMatch\":\"/前端/\",\"link\":\"/前端/Vue3/axios\"},{\"text\":\"LLM\",\"activeMatch\":\"/LLM/\",\"link\":\"/LLM/LangChain/quick_start\"},{\"text\":\"环境搭建\",\"activeMatch\":\"/环境搭建/\",\"link\":\"/环境搭建/docker/mysql\"}],\"sidebar\":{\"/工具/\":[{\"text\":\"Git\",\"collapsed\":false,\"items\":[{\"text\":\"同时推送Gitee和GitHub\",\"link\":\"/工具/Git/同时推送Gitee和GitHub\"},{\"text\":\"Git的基本使用\",\"link\":\"/工具/Git/Git的基本使用\"},{\"text\":\"gitignore\",\"link\":\"/工具/Git/gitignore\"}]}],\"/Linux/\":[{\"text\":\"Linux基础入门\",\"link\":\"/Linux/Linux基础入门\"},{\"text\":\"虚拟机相关\",\"link\":\"/Linux/虚拟机相关\"},{\"text\":\"常用命令备忘\",\"link\":\"/Linux/常用命令备忘\"}],\"/爬虫/\":[{\"text\":\"导论\",\"link\":\"/爬虫/导论\"},{\"text\":\"抓包\",\"link\":\"/爬虫/抓包\"},{\"text\":\"bs4解析\",\"link\":\"/爬虫/bs4解析\"},{\"text\":\"xpath解析\",\"link\":\"/爬虫/xpath解析\"},{\"text\":\"登录流程\",\"link\":\"/爬虫/登录流程\"},{\"text\":\"scrapy\",\"link\":\"/爬虫/scrapy\"},{\"text\":\"selenium\",\"link\":\"/爬虫/selenium\"},{\"text\":\"jsonpath解析\",\"link\":\"/爬虫/jsonpath解析\"}],\"/测试/\":[{\"text\":\"faker数据随机生成\",\"link\":\"/测试/faker数据随机生成\"},{\"text\":\"Jenkins\",\"link\":\"/测试/Jenkins\"},{\"text\":\"unittest\",\"link\":\"/测试/unittest\"},{\"text\":\"性能测试\",\"collapsed\":false,\"items\":[{\"text\":\"基础概念\",\"link\":\"/测试/性能测试/基础概念\"}]},{\"text\":\"pytest\",\"collapsed\":false,\"items\":[{\"text\":\"pytest基础\",\"link\":\"/测试/pytest/pytest基础\"},{\"text\":\"yaml文件\",\"link\":\"/测试/pytest/yaml文件\"},{\"text\":\"日志\",\"link\":\"/测试/pytest/日志\"}]}],\"/Python/\":[{\"text\":\"原理类\",\"collapsed\":false,\"items\":[{\"text\":\"内存管理\",\"link\":\"/Python/原理类/内存管理\"},{\"text\":\"单例模式\",\"link\":\"/Python/原理类/单例模式\"},{\"text\":\"多进程多线程协程\",\"link\":\"/Python/原理类/多进程多线程协程\"},{\"text\":\"深浅拷贝\",\"link\":\"/Python/原理类/深浅拷贝\"},{\"text\":\"自省\",\"link\":\"/Python/原理类/自省\"},{\"text\":\"迭代器和生成器\",\"link\":\"/Python/原理类/迭代器和生成器\"},{\"text\":\"闭包和装饰器\",\"link\":\"/Python/原理类/闭包和装饰器\"},{\"text\":\"高阶函数\",\"link\":\"/Python/原理类/高阶函数\"},{\"text\":\"魔法方法\",\"link\":\"/Python/原理类/魔法方法\"},{\"text\":\"鸭子类型\",\"link\":\"/Python/原理类/鸭子类型\"},{\"text\":\"依赖注入\",\"link\":\"/Python/原理类/依赖注入\"}]},{\"text\":\"工具类\",\"collapsed\":false,\"items\":[{\"text\":\"logging\",\"link\":\"/Python/工具类/logging\"}]},{\"text\":\"基础\",\"collapsed\":false,\"items\":[{\"text\":\"练习题\",\"link\":\"/Python/基础/练习题\"}]}],\"/前端/\":[{\"text\":\"Vue3\",\"collapsed\":false,\"items\":[{\"text\":\"axios\",\"link\":\"/前端/Vue3/axios\"},{\"text\":\"面试\",\"link\":\"/前端/Vue3/面试\"}]},{\"text\":\"前端三件套\",\"collapsed\":false,\"items\":[{\"text\":\"HTML\",\"collapsed\":false,\"items\":[{\"text\":\"HTML基础\",\"link\":\"/前端/前端三件套/HTML/HTML基础\"}]},{\"text\":\"CSS\",\"collapsed\":false,\"items\":[{\"text\":\"css3自定义属性\",\"link\":\"/前端/前端三件套/CSS/css3自定义属性\"},{\"text\":\"css基础入门\",\"link\":\"/前端/前端三件套/CSS/css基础入门\"},{\"text\":\"flexbox布局\",\"link\":\"/前端/前端三件套/CSS/flexbox布局\"},{\"text\":\"grid布局\",\"link\":\"/前端/前端三件套/CSS/grid布局\"},{\"text\":\"动画\",\"link\":\"/前端/前端三件套/CSS/动画\"},{\"text\":\"媒体查询\",\"link\":\"/前端/前端三件套/CSS/媒体查询\"},{\"text\":\"属性\",\"link\":\"/前端/前端三件套/CSS/属性\"}]},{\"text\":\"js\",\"collapsed\":false,\"items\":[{\"text\":\"DOM操作\",\"link\":\"/前端/前端三件套/js/DOM操作\"},{\"text\":\"js入门\",\"link\":\"/前端/前端三件套/js/js入门\"},{\"text\":\"属性描述符\",\"link\":\"/前端/前端三件套/js/属性描述符\"},{\"text\":\"高阶函数\",\"link\":\"/前端/前端三件套/js/高阶函数\"}]},{\"text\":\"面试\",\"collapsed\":false,\"items\":[{\"text\":\"基本题\",\"link\":\"/前端/前端三件套/面试/基本题\"}]},{\"text\":\"实战案例\",\"collapsed\":false,\"items\":[{\"text\":\"聊天页面\",\"link\":\"/前端/前端三件套/实战案例/聊天页面\"}]}]}],\"/Python框架/\":[{\"text\":\"Django\",\"collapsed\":false,\"items\":[{\"text\":\"接口文档\",\"link\":\"/Python框架/Django/接口文档\"},{\"text\":\"熟悉流程\",\"collapsed\":false,\"items\":[{\"text\":\"部署博客\",\"link\":\"/Python框架/Django/熟悉流程/部署博客\"}]},{\"text\":\"4-1环境搭建\",\"link\":\"/Python框架/Django/4-1环境搭建\"},{\"text\":\"4-2settings配置\",\"link\":\"/Python框架/Django/4-2settings配置\"},{\"text\":\"4-3路由定义与使用\",\"link\":\"/Python框架/Django/4-3路由定义与使用\"},{\"text\":\"4-4请求与响应\",\"link\":\"/Python框架/Django/4-4请求与响应\"},{\"text\":\"4-5session_cookie\",\"link\":\"/Python框架/Django/4-5session_cookie\"},{\"text\":\"4-6类视图\",\"link\":\"/Python框架/Django/4-6类视图\"},{\"text\":\"4-7模板引擎\",\"link\":\"/Python框架/Django/4-7模板引擎\"},{\"text\":\"虚拟环境\",\"link\":\"/Python框架/Django/虚拟环境\"}]},{\"text\":\"Flask\",\"collapsed\":false,\"items\":[{\"text\":\"start\",\"link\":\"/Python框架/Flask/start\"},{\"text\":\"Flask-wtf&wtfforms\",\"link\":\"/Python框架/Flask/Flask-wtf&wtfforms\"},{\"text\":\"Flask-SQLAlchemy\",\"link\":\"/Python框架/Flask/Flask-SQLAlchemy\"}]}],\"/其他/\":[{\"text\":\"面经\",\"collapsed\":false,\"items\":[{\"text\":\"大疆\",\"link\":\"/其他/面经/大疆\"},{\"text\":\"差旅1号\",\"link\":\"/其他/面经/差旅1号\"},{\"text\":\"广州嘉为科技公司-python\",\"link\":\"/其他/面经/广州嘉为科技公司-python\"},{\"text\":\"得物\",\"link\":\"/其他/面经/得物\"},{\"text\":\"招商银行\",\"link\":\"/其他/面经/招商银行\"},{\"text\":\"百度\",\"link\":\"/其他/面经/百度\"}]},{\"text\":\"八股\",\"collapsed\":false,\"items\":[{\"text\":\"Linux\",\"link\":\"/其他/八股/Linux\"},{\"text\":\"前端\",\"collapsed\":false,\"items\":[{\"text\":\"事件循环&异步\",\"link\":\"/其他/八股/前端/事件循环&异步\"},{\"text\":\"HTML\",\"collapsed\":false,\"items\":[{\"text\":\"文档声明\",\"link\":\"/其他/八股/前端/HTML/文档声明\"},{\"text\":\"替换元素\",\"link\":\"/其他/八股/前端/HTML/替换元素\"},{\"text\":\"语义化&SEO&微格式\",\"link\":\"/其他/八股/前端/HTML/语义化&SEO&微格式\"},{\"text\":\"页面可见性\",\"link\":\"/其他/八股/前端/HTML/页面可见性\"}]},{\"text\":\"CSS\",\"collapsed\":false,\"items\":[{\"text\":\"单位\",\"link\":\"/其他/八股/前端/CSS/单位\"},{\"text\":\"居中的方式\",\"link\":\"/其他/八股/前端/CSS/居中的方式\"}]}]},{\"text\":\"数据库\",\"collapsed\":false,\"items\":[{\"text\":\"log\",\"link\":\"/其他/八股/数据库/log\"},{\"text\":\"mysql的执行引擎\",\"link\":\"/其他/八股/数据库/mysql的执行引擎\"},{\"text\":\"redis\",\"link\":\"/其他/八股/数据库/redis\"},{\"text\":\"sql语句的执行\",\"link\":\"/其他/八股/数据库/sql语句的执行\"},{\"text\":\"慢查询\",\"link\":\"/其他/八股/数据库/慢查询\"},{\"text\":\"索引失效的场景\",\"link\":\"/其他/八股/数据库/索引失效的场景\"},{\"text\":\"事务\",\"collapsed\":false,\"items\":[{\"text\":\"事务的四大特性\",\"link\":\"/其他/八股/数据库/事务/事务的四大特性\"},{\"text\":\"事务的隔离级别\",\"link\":\"/其他/八股/数据库/事务/事务的隔离级别\"}]},{\"text\":\"进阶\",\"collapsed\":false,\"items\":[{\"text\":\"窗口函数\",\"link\":\"/其他/八股/数据库/进阶/窗口函数\"}]}]},{\"text\":\"测开\",\"collapsed\":false,\"items\":[{\"text\":\"bug\",\"link\":\"/其他/八股/测开/bug\"},{\"text\":\"性能测试\",\"link\":\"/其他/八股/测开/性能测试\"},{\"text\":\"测试的流程\",\"link\":\"/其他/八股/测开/测试的流程\"},{\"text\":\"测试的理解\",\"link\":\"/其他/八股/测开/测试的理解\"},{\"text\":\"软件测试\",\"link\":\"/其他/八股/测开/软件测试\"},{\"text\":\"软件质量\",\"link\":\"/其他/八股/测开/软件质量\"}]},{\"text\":\"数据结构\",\"collapsed\":false,\"items\":[{\"text\":\"二分法\",\"link\":\"/其他/八股/数据结构/二分法\"},{\"text\":\"二叉树\",\"link\":\"/其他/八股/数据结构/二叉树\"},{\"text\":\"回溯\",\"link\":\"/其他/八股/数据结构/回溯\"},{\"text\":\"滑动窗口最大值\",\"link\":\"/其他/八股/数据结构/滑动窗口最大值\"},{\"text\":\"数组\",\"collapsed\":false,\"items\":[{\"text\":\"蛇形填数\",\"link\":\"/其他/八股/数据结构/数组/蛇形填数\"}]},{\"text\":\"背包\",\"collapsed\":false,\"items\":[{\"text\":\"01背包\",\"link\":\"/其他/八股/数据结构/背包/01背包\"}]},{\"text\":\"链表\",\"collapsed\":false,\"items\":[{\"text\":\"两两交换链表中的节点\",\"link\":\"/其他/八股/数据结构/链表/两两交换链表中的节点\"},{\"text\":\"单链表\",\"link\":\"/其他/八股/数据结构/链表/单链表\"},{\"text\":\"反转链表\",\"link\":\"/其他/八股/数据结构/链表/反转链表\"}]}]},{\"text\":\"计网\",\"collapsed\":false,\"items\":[{\"text\":\"CDN\",\"link\":\"/其他/八股/计网/CDN\"},{\"text\":\"cookie&session\",\"link\":\"/其他/八股/计网/cookie&session\"},{\"text\":\"DNS查询过程\",\"link\":\"/其他/八股/计网/DNS查询过程\"},{\"text\":\"http常见状态码\",\"link\":\"/其他/八股/计网/http常见状态码\"},{\"text\":\"OSI模型\",\"link\":\"/其他/八股/计网/OSI模型\"},{\"text\":\"url到页面展示\",\"link\":\"/其他/八股/计网/url到页面展示\"},{\"text\":\"强缓存和协商缓存\",\"link\":\"/其他/八股/计网/强缓存和协商缓存\"},{\"text\":\"传输层\",\"collapsed\":false,\"items\":[{\"text\":\"TCP&UDP\",\"link\":\"/其他/八股/计网/传输层/TCP&UDP\"}]},{\"text\":\"物理层\",\"collapsed\":false,\"items\":[{\"text\":\"奈氏准则&香农公式\",\"link\":\"/其他/八股/计网/物理层/奈氏准则&香农公式\"}]},{\"text\":\"应用层\",\"collapsed\":false,\"items\":[{\"text\":\"http&https\",\"link\":\"/其他/八股/计网/应用层/http&https\"},{\"text\":\"http\",\"link\":\"/其他/八股/计网/应用层/http\"},{\"text\":\"http1.0各个版本\",\"link\":\"/其他/八股/计网/应用层/http1.0各个版本\"}]}]},{\"text\":\"操作系统\",\"collapsed\":false,\"items\":[{\"text\":\"存储管理\",\"link\":\"/其他/八股/操作系统/存储管理\"},{\"text\":\"操作系统安全及虚拟化技术概述\",\"link\":\"/其他/八股/操作系统/操作系统安全及虚拟化技术概述\"},{\"text\":\"操作系统概述及基本概念\",\"link\":\"/其他/八股/操作系统/操作系统概述及基本概念\"},{\"text\":\"文件系统\",\"link\":\"/其他/八股/操作系统/文件系统\"},{\"text\":\"死锁\",\"link\":\"/其他/八股/操作系统/死锁\"},{\"text\":\"输入输出\",\"link\":\"/其他/八股/操作系统/输入输出\"},{\"text\":\"进程与线程\",\"link\":\"/其他/八股/操作系统/进程与线程\"},{\"text\":\"面试八股\",\"link\":\"/其他/八股/操作系统/面试八股\"}]},{\"text\":\"其他\",\"collapsed\":false,\"items\":[{\"text\":\"汇编\",\"collapsed\":false,\"items\":[{\"text\":\"串指令\",\"link\":\"/其他/八股/其他/汇编/串指令\"},{\"text\":\"前置知识\",\"link\":\"/其他/八股/其他/汇编/前置知识\"},{\"text\":\"宏汇编\",\"link\":\"/其他/八股/其他/汇编/宏汇编\"},{\"text\":\"寄存器\",\"link\":\"/其他/八股/其他/汇编/寄存器\"},{\"text\":\"寻址方式\",\"link\":\"/其他/八股/其他/汇编/寻址方式\"},{\"text\":\"数据传送指令\",\"link\":\"/其他/八股/其他/汇编/数据传送指令\"},{\"text\":\"程序设计综合\",\"link\":\"/其他/八股/其他/汇编/程序设计综合\"},{\"text\":\"逻辑运算与移位指令\",\"link\":\"/其他/八股/其他/汇编/逻辑运算与移位指令\"}]},{\"text\":\"网安\",\"collapsed\":false,\"items\":[{\"text\":\"网络安全\",\"link\":\"/其他/八股/其他/网安/网络安全\"}]}]}]},{\"text\":\"项目\",\"collapsed\":false,\"items\":[{\"text\":\"项目部署\",\"collapsed\":false,\"items\":[{\"text\":\"web\",\"link\":\"/其他/项目/项目部署/web\"},{\"text\":\"vitepress\",\"collapsed\":false,\"items\":[{\"text\":\"GithubPages部署\",\"link\":\"/其他/项目/项目部署/vitepress/GithubPages部署\"},{\"text\":\"netlify部署\",\"link\":\"/其他/项目/项目部署/vitepress/netlify部署\"},{\"text\":\"Nginx部署\",\"link\":\"/其他/项目/项目部署/vitepress/Nginx部署\"}]}]}]}],\"/LLM/\":[{\"text\":\"LangChain\",\"collapsed\":false,\"items\":[{\"text\":\"quick_start\",\"link\":\"/LLM/LangChain/quick_start\"},{\"text\":\"Prompt\",\"link\":\"/LLM/LangChain/Prompt\"},{\"text\":\"Model\",\"link\":\"/LLM/LangChain/Model\"},{\"text\":\"OutputParser\",\"link\":\"/LLM/LangChain/OutputParser\"},{\"text\":\"LCEL表达式与Runnable可运行协议\",\"link\":\"/LLM/LangChain/LCEL表达式与Runnable可运行协议\"}]}],\"/环境搭建/\":[{\"text\":\"docker\",\"collapsed\":false,\"items\":[{\"text\":\"mysql\",\"link\":\"/环境搭建/docker/mysql\"}]}]}},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
    
  </body>
</html>